Is there a known characterization of the rings $R$ (containing $1$) with this property: every element of $R$ is a sum of two commuting idempotents.

$\begingroup$ May I ask where this question comes from? It is a very fun question, and I can solve it for finite rings. On the other hand, with the finite hypothesis, it would make an excellent challenging homework question for a class on noncommutative ring theory, and I'd rather not give away the answer if it is. $\endgroup$– David E SpeyerSep 18 '13 at 16:50

$\begingroup$ Antiinverse rings, see journals.cambridge.org/abstract_S000497270002668X and elib.mi.sanu.ac.rs/files/journals/publ/53/n047p225.pdf (also math.okayamau.ac.jp/mjou/mjou146/mjou_pdf/mjou_33/… is related) $\endgroup$– user46855Feb 15 '14 at 15:31
If $x$ and $y$ are two commuting idempotents, then $(x+y)^3 = x+y+6xy$, $(x+y)^2=x+y+2xy$, so $z=x+y$ satisfies the equation $z^33z^2+2z=0$. Plugging $z=3$ into the equation, we obtain $6=0$. So the ring is a product of a ring of characteristic $3$ and a ring of characteristic $2$.
In the ring of characteristic $2$, $(x+y)^2=(x+y)$, so every element is idempotent. This implies that the ring is commutative, because
$$0 = (a+b)ab=(a+b)^2a^2b^2 = ab+ba = abba$$
So the ring is a Boolean algebra  the ring of locally constant functions to $\mathbb F_2$ on a compact, totally disconnected topological space.
In the ring of characteristic $3$, as Clement points out the ring is commutative, because we have $a^3=a$, so if $a$ is invertible then $a^2=1$, so in the group of units every element has order $2$, so the group of units is commutative. But every element is the sum of two units: $a= (1aa^2) + (a^2a1)$, so the whole ring is commutative.
Being reduced, the intersection of all the prime ideals is $0$, but the field of fractions of a prime ideal is a field where every element is its own cube, hence is $\mathbb F_3$. So the ring embeds into a product of copies of $\mathbb F_3$. By the same logic as in the Boolean algebras case that the ring is the ring of locally constant functions to $\mathbb F_3$ on a compact totally disconnected topological space:
Let $R$ be our ring, then $\operatorname{Spec} R$ is a topological space by standard ring theory. Since each prime ideal has quotien $\mathbb F_3$, and element $x\in R$ corresponds to a function from this space to $\mathbb F_3$. Since the sets $(x=0)$, $(x=1)$, $(x=2)$ are each closed, because they correspond to ideals, the function must be locally constant. Conversely, a locally constant function actually corresponds to an element of the ring since it locally looks like an element of the ring. The space is totally disconnected since each pair of distinct points must be distinguished by some locally constant function.
So the final answer is that such a ring consists of all the locally constant functions to $\mathbb F_2$ and $\mathbb F_3$, respectively, on a pair of compact, totally disconnected topological spaces. Conversely, any such ring will have every element the sum of two idempotents.
EDIT: In a ring where every element is the sum of $n$ commuting idempotents, every element will satisfy $\prod_{i=0}^{n} (zi)=0$, so by plugging in $n+1$, we will have $n!=0$. So the ring will decompose as a product of $p$power parts for $p\leq n$ prime. Mod $p^k$, each element which is the sum of $n$ idempotents satisfies $\prod_{i=0}^{\min(n, p^k1)} (zi)=0$. In particular, mod $p$ we will have $z^pz=0$. So mod $2$ and mod $3$ the ring will still have the same form, but I think at some point (mod $4$? mod $5$? mod $7$?) it stops being necessarily commutative.
In the finite case, and the commutative case, things get simpler.

2$\begingroup$ If the ring has characteristic 3, then your equation yields $z^3=z$ for all $z$ in the ring, which classically yields that the ring is commutative. $\endgroup$ Sep 18 '13 at 17:29

$\begingroup$ In fact, rings satisfying z3=z are I believe subdirect products of division rings. Since the only characteristic 3 division ring where each element is a sum of 2 commuting idempotents is Z/3, we get that the answer is products of copies of Z/2 and Z/3. $\endgroup$ Sep 18 '13 at 17:46

$\begingroup$ Benjamin, there are subdirect products of division rings that are not direct products of division rings. Consider the subring of $(\mathbb{Z}/3)^\mathbb{N}$ consisting of the ultimately constant sequences. It is not a direct product of copies of $\mathbb{Z}/3$. $\endgroup$ Sep 18 '13 at 17:50

$\begingroup$ Ok, I had falsely assumed every subdirect product is direct for these rings. (I fixed my comment). $\endgroup$ Sep 18 '13 at 17:54

1$\begingroup$ A question: Why is $1a^2$ invertible? I see how to invert $a^2+a1$, since $(a^2+a1)(1aa^2)=1$, but not $1a^2$. (Of course ultimately this is irrelevant as we can also show commutativity by other means.) $\endgroup$ Sep 18 '13 at 21:30
The trivial/elementary proof (in particular, it does not use the axiom choice).
A ring $R$ satisfies your condition iff it satisfies the identity $x^3=x$.
Pf.
Will shows above with a short computation that if $R$ satisfies the condition, then the characteristic divides $6$. So if $z=e+f$ with $e,f$ commuting idempotents, then $z^3=(e+f)^3=e+6ef+f = e+f=z$.
Suppose $z^3=z$ for all elements of $R$. Now $R$ has characteristic dividing $6$ since $2=(1+1)^3=8$. Thus we have $R$ is a product $R_1\times R_2$ of a ring $R_1$ of characteristic $2$ and $R_2$ of characteristic $3$. The ring $R_1$ is boolean (using $z1=(z1)^3=z^33z^2+3z1=z^21$, whence $z^2=z$) and so all elements are idempotent and we are done. So it suffices to handle $R_2$, i.e., assume the characteristic is $3$.
Note $z^2$ is idempotent and $z=z^2+(zz^2)$. We claim the latter is idempotent. Then $(zz^2)^2= z^22z^3+z^4=2z^22z=zz^2$. Done.
Answer. I believe that the answer is that the ring be a subdirect product of copies of $Z/2$ and $Z/3$, which in this case is equivalent to being in the variety of rings generated by $Z/6$.
My original revised answer below says that a ring satisfying the desired condition is a subdirect product of copies of $Z/2$ and $Z/3$ and hence in the variety generated by $Z/6$.
Suppose $R$ is a ring in the variety generated by $Z/6$. Since $R$ is a direct limit of finitely generated rings and your property is closed under direct limit, we may assume that $R$ is finitely generated. But then $R$ is finite because a variety generated by a finite ring is locally finite.
But if $R$ is finite and in this variety, then $R$ is a reduced finite commutative ring and hence a finite direct product of domains belonging to the variety generated by $Z/6$. But $Z/2$ and $Z/3$ are the only domains in this variety.
Original Revised Answer. A necessary condition is that $R$ is a subdirect product of copies of $Z/2$ and $Z/3$.
Claim 1: The class of rings satisfying your property is closed under direct product and homomorphic images.
Pf. Exercise.
Claim 2: If the ring is indecomposable (not a direct product), then the ring either is a boolean algebra or satisfies $z^3=z$. Pf. See Will's answer and the comments.
Claim 3: the ring $R$ is reduced (i.e., has no nonzero nilpotents). Pf. Clear since it is a product of a ring satisfying $z^2=z$ and one satisfying $z^3=z$.
Theorem 12.7 in Lam's book on noncommutative 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 subdirect product of $Z/2$ or $Z/3$.
Now boolean algebras (=subdirect products of $Z/2$) all have the desired property so it remains to see which subdirect products of $Z/3$ have the property.

$\begingroup$ I am confused. Not every Boolean algebra is a direct product of copies of $\mathbb{Z}/2$. (Or maybe I'm not sure what "direct" in direct product means.) $\endgroup$– Todd Trimble ♦Sep 18 '13 at 17:53

$\begingroup$ ok, I was hasty. I was thinking of finite subdirect products. Let me fix. $\endgroup$ Sep 18 '13 at 17:55

$\begingroup$ Any subdirect product of $\mathbb{Z}/3$ has this property. Any element $z\in R$ can be considered as a continuous function $z:\operatorname{Spec} R\to \mathbb{Z}/3$. For $i\in\mathbb{Z}/3$, let $A_i=z^{1}(\{i\})$. Then these sets are clopen, and $z=1_{A_1\cup A_2}+1_{A_2}$. $\endgroup$ Sep 18 '13 at 18:33

$\begingroup$ @EricWofsey, this is Will's version of the argument. My first version was to reduce to the finitely generated case, where the ring is finite and no Zariski topology is needed. Now I have the elementary proof. $\endgroup$ Sep 18 '13 at 18:48

1$\begingroup$ The proof can be simplified in one direction. My equation $z^33z^2+2z=0$ is just $(z1)^3=(z1)$. $\endgroup$ Sep 18 '13 at 18:51