You're assuming that $R$ must be a domain. It is possible (or at least you haven't yet ruled it out) that two nonzero elements can multiply to zero. You also assume that $R$ has a unit element in order to prove it has one, which is of course illicit.
Here are some comments that might help. I will use 'ring' to mean "ring, possibly without identity." Rings with $x^2=x$ for all $x$ are called Boolean. You can show, by taking $(x+x)^2$, that all such rings must have characteristic two. This allows us to view such rings as vector spaces over $\mathbb Z_2$. In particular, a finite Boolean ring must have $2^n$ elements for some integer $n$.
For a complete solution, see here.