The answer is that $R$ is a direct product of copies of $Z/2$ and $Z/3$.
Claim 1: The class of rings satisfying your property is closed under direct product.
Pf. Exercise.
Claim 2: We may assume without loss of generality that $R$ is subdirectly irreducible. Pf. Clearly your property is closed under homomorphic image so a subdirect decomposition of your ring will be into rings of your form. It is not too hard to see that a subdirect (meaning I didn't check to carefully) that subdirect products of the above rings are actually direct products.
Claim 3: The ring either is a boolean algebra or satisfies $z^3=z$. Pf. See Will's answer and the comments.
Claim 4: the ring $R$ is reduced (i.e., has no non-zero nilpotents). Pf. Clear since it satisfies $z^2=z$ or $z^3=z$.
Theorem 12.7 in Lam's book on non-commutative rings shows a subdirectly irreducible reduced ring is an integral domain. Since 0,1 are the unique idempotents of an integral domain, we conclude that $R$ is $Z/2$ or $Z/3$.