If $A\simeq\prod A_i$ then $\sum e_i=1$ Given $A$ commutative ring with unity. If we have rings $A_1,\dots, A_n$such that $A\simeq A_1\times \dots \times A_n$ there are $e_1,\dots,e_n$ idempotent elements of $A$ such that $e_1+\dots+e_n = 1$ and $e_i e_j =0$ if $i\neq j$.
I'm not sure how general the proof should be written...
The isomorphic relation suggest that if $f$ defines the isomorphism then there is a $(a_1,\dots, a_n)\in \prod A_i$ such that $f(a_1,\dots,a_n)=1\in A$. Could it work thinking of the idemmpotent terms as $e_i=(0,\dots,0, a_i,0, \dots,0)?$ This should satisfy $e_i e_j =0$ if $i\neq j$. But I have two problems with it (1) I don't see why $e_i$ should idempotent as no assumptions in regard to the existence of idempotent elements in $A_i$ has been made. (2) The sum $\sum e_i=1$ has no reason to be true.
 A: Robert Lewis's answer gives a good bit of detail. If you are looking for a more terse answer:
Your idea is right, for each $j$ let $e_j = (0,\dotsc,0,a_j,0,\dotsc,0)$, where the $a_j$ are defined by $f(a_1,\dotsc,a_n)=1 \in A$.
The first key point is to identify the $a_i$'s. As Robert Lewis explains, each $a_i = \pi_i(1)$ is a multiplicative identity in $A_i$. In fact, since $f$ is an isomorphism, $(a_1,\dotsc,a_n)$ is a multiplicative identity in $P = \prod A_i$; now for any $x \in A_i$, consider the multiplication
$$
  (0,\dotsc,0,x,0,\dotsc,0) \cdot (a_1,\dotsc,a_i,\dotsc,a_n) = (0,\dotsc,a_i x, \dotsc 0).
$$
Since $(a_1,\dotsc,a_n)$ is a multiplicative identity, then $a_i x = x \in A_i$. So each $a_i$ is a multiplicative identity in $A_i$. (If you're worried, you can check they are also right identities, or better yet show each $A_i$ is commutative.) We can henceforth denote each $a_i$ by $1_{A_i}$.
Now we follow your idea. For each $j$, let $e_j = (0,\dotsc,0,1_{A_j},0,\dotsc,0) \in \prod A_i$, the element with $1$ in the $j$th entry and all other entries $0$. You can verify that each $e_j^2 = e_j$; $e_i e_j = 0$ for $i \neq j$; and $\sum e_j = (1,1,\dotsc,1) = 1_P$ (where $P = \prod A_j$). You can verify these things by directly computing with the "vectors" for the $e_j$.
The $f(e_j)$ are the desired idempotent elements of $A$.
