The purpose of this post is to prove:
(a) If $R$ is a ring (i.e. an associative ring with $1$), then any two by two matrix with entries in $R$ is a $\mathbb Z$-linear combination of products of two idempotents.
Proof: We have
\begin{align*}
\begin{pmatrix}a&b\\ c&d\end{pmatrix}&=\begin{pmatrix}1&a-1\\ 0&0\end{pmatrix}\begin{pmatrix}1&0\\ 1&0\end{pmatrix}+\begin{pmatrix}1&b+1\\ 0&0\end{pmatrix}-\begin{pmatrix}1&1\\ 0&0\end{pmatrix}\\ \\
&+\begin{pmatrix}0&0\\ d-1&1\end{pmatrix}\begin{pmatrix}0&1\\ 0&1\end{pmatrix}+\begin{pmatrix}1&0\\ c+1&0\end{pmatrix}-\begin{pmatrix}1&0\\ 1&0\end{pmatrix}.
\end{align*}
QED
George Lowther proved:
(b) If $R$ is a ring, then any two by two matrix with entries in $R$ is a $\mathbb Z$-linear combination of products of three idempotents.
George also explained that, in order to answer the question, it sufficed to prove:
(c) If $R$ is a ring, then any two by two matrix with entries in $R$ is a $\mathbb Z$-linear combination of products of idempotents.
Going from (b) to (a) reduces the number of factors from three down to two. This number cannot be reduced further, because, as George observed in a comment, a two by two matrix with entries in $R$ is not in general a $\mathbb Z$-linear combination of idempotents.
Indeed, for trace reasons,
$$
\begin{pmatrix}\frac12&0\\ 0&0\end{pmatrix}
$$
is not a $\mathbb Z$-linear combination of idempotents of $M_2(\mathbb Q)$.
In fact George shows that, if $R$ is a domain, then the condition that any two by two matrix with entries in $R$ is a $\mathbb Z$-linear combination of idempotents is equivalent to $R$ being a quotient of $\mathbb Z$.
The question about the least number of factors was raised by Jonas Meyer in a comment. Things will become clearer if we generalize slightly the setting.
Let $K$ be a commutative ring and $R$ a $K$-algebra (associative with $1$).
By our previous considerations, any two by two matrix with entries in $R$ is a $K$-linear combination of products of two idempotents, but in general not a $K$-linear combination of idempotents.
Say that $R$ is $K$-nice, or nice over $K$, if any two by two matrix with entries in $R$ is a $K$-linear combination idempotents.
Jonas asked if $\operatorname{End}_K(V)$ (for $V$ a $K$-vector space) is $K$-nice.
One can also ask which rings are nice over their center.
In view of the above proof, $R$ is $K$-nice if and only if any matrix of the form
$$
\begin{pmatrix}a&0\\ 0&0\end{pmatrix}
$$
is a $K$-linear combination of idempotents.