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.
In this answer, I am going to assume that no $A_k$ is the zero ring $\{0\}$:
$\forall k, 1 \le k \le n, A_k \ne \{0\}; \tag 1$
this assumption is made without loss of generality, since it is easy to see that if $A_k = \{0\}$ for some $k$, there is a ring isomorphism
$\phi: A_1 \times A_2 \times \ldots A_{k - 1} \times A_k \times A_{k + 1} \times \ldots A_n \simeq A_1 \times A_2 \times A_{k - 1} \times A_{k + 1} \times \ldots \times A_n \tag 2$
given by
$\phi(a_1, a_2, \ldots, a_{k - 1}, 0, a_{k + 1}, \ldots, a_n) = (a_1, a_2, \ldots, a_{k - 1}, a_{k + 1}, \ldots, a_n); \tag 3$
by repeatedly employing such isomorphisims we may reduce any finite product $A_1 \times A_2 \times \ldots \times A_n$ to one which either has no zero factors or is the ring $\{0\}$ itself; in this latter case we have
$A \simeq \{0\}, \tag 4$
$1 = 0$ in $A$, and the result is trivial. Therefore (1) imposes no essential restriction on the result we seek to prove.
In the following I will deploy the notation
$P = A_1 \times A_2 \times \ldots \times A_n = \displaystyle \prod_1^n A_i \tag 5$
($P$ for product), which saves me a many a keystroke when typing $\LaTeX$.
If $f: A \to A_1 \times A_2 \times \ldots \times A_n = \displaystyle \prod_1^n A_i = P, \tag 6$
denotes an isomorphism 'twixt $A$ and $\prod_1^n A_i = P$, then $f(\mathbf 1_A)$, where $\mathbf 1_A$ is the unit of $A$, must be the unique multiplicative unit $\mathbf 1_P$ of $P$; thus $P$ is unital with unit $\mathbf 1_P = f(\mathbf 1_A)$.
If we donote the projection onto the $j$-th component of $\prod_1^n A_i$ by
$\pi_j: \displaystyle \prod_1^n A_i \to A_j, \tag 7$
that is, for
$a = (a_1, a_2, \ldots, a_j, \ldots, a_n) \in P \tag 8$
we have
$\pi_j(a) = \pi_j(a_1, a_2, \ldots, a_j, \ldots, a_n) = a_j \in A_j, \tag 9$
then we may also define the injection
$\iota_j: A_j \to P = \displaystyle \prod_1^n A_i \tag{10}$
by
$\iota_j(a_j) = (0, 0, \ldots, a_j, \ldots, 0) = (\delta_{1j}a_j, \delta_{2j}a_j, \ldots, \delta_{ij}a_j, \ldots, \delta_{nj}a_j), \tag{11}$
where $\delta_{ij}$ is the usual Kronecker symbol; that is
$\delta_{ij} = 1, \; i = j, \tag{12}$
$\delta_{ij} = 0, \; i \ne j; \tag{13}$
thus (7) is equivalent to
$(\iota_j(a_j))_i = \delta_{ij} a_j, \tag{14}$
that is, the $i$-th component of $\iota_j(a_j)$ is $0$ when $i \ne j$, and $a_j$ for $i = j$. It is easy to see that both the $\pi_j$ and the $i_j$ are homomorphisms, and that
$a_j \in A_j \Longrightarrow \pi_j\iota_j(a_j) = a_j, \tag {15}$
that is,
$\pi_j \iota_j = \mathbf I_j, \tag{16}$
where $\mathbf I_j$ is the identity map on $A_j$; we also have, with $a$ as in (8),
$\iota_j \pi_j(a) = \iota_j(a_j) = (0, 0, \ldots, a_j, \ldots, 0) = (\delta_{1j}a_j, \delta_{2j}a_j, \ldots, \delta_{ij}a_j, \ldots, \delta_{nj}a_j). \tag{17}$
We note that it is easy to see that
$\text{Range}(\pi_j) = A_j, \tag{18}$
and
$\ker \iota_j = \{0\}. \tag{19}$
Bearing these preliminary remarks in mind, we set
$\pi_j(\mathbf 1_P) = \mathbf 1_j \in A_j, \tag{20}$
and thus we see that $A_j$ is unital with unit $\mathbf 1_j$; this follows from the fact that $\pi_j$ is surjective, hence for any $c_j \in A_j$ there exists $b_j \in P$ such that
$\pi_j(b_j) = c_j; \tag{21}$
we have
$c_j = \pi_j(b_j) = \pi_j(\mathbf 1_P b_j) = \pi_j(\mathbf 1_P) \pi_j(b_j) = \pi_j(\mathbf 1_P)c_j \tag{22}$
and
$c_j = \pi_j(b_j) = \pi_j(b_j \mathbf 1_P) = \pi_j(b_j) \pi_j(\mathbf 1_P) = c_j \pi_j(\mathbf 1_P); \tag{23}$
(22) and (23) together show that $\pi_j(\mathbf 1_P)$ is either $0_j$ or the multiplicative unit of $A_j$; we can rule out $\pi_j(\mathbf 1_P) = 0_j$ since this implies (via (22) and (23)) that $c_j = 0_j$ for all $c_j \in A_j$, impossible by (1); thus we see that $\mathbf 1_j$ as defined by (20) is the (non-zero) multiplicative unit of $A_j$.
Now set
$e_j = \iota_j(\mathbf 1_j) \in P; \tag{24}$
we have
$e_j^2 = (\iota_j(\mathbf 1_j))^2 =\iota_j(\mathbf 1_j^2) = \iota_j(\mathbf 1_j) = e_j; \tag{25}$
thus $e_j$ is an idempotent in $P$;
$e_j \ne 0 \tag{26}$
since $\iota_j$ is injective and $\mathbf 1_j \ne 0_j$ in $A_j$. We have now established the existence of $n$ non-zero idempotents $e_i$, $1 \le i \le n$, in $P$.
Further progress towards our goal will be facilitated via the aid of the following
Fact:
$\forall a, b \in P ([a = b] \Longleftrightarrow [\forall j, 1 \le j \le n, \pi_j(a) = \pi_j(b)]), \tag{27}$
for which we offer the following
Proof of Fact: It is clear that
$[a = b] \Longrightarrow [\forall j, 1 \le j \le n, \pi_j(a) = \pi_j(b)], \tag{28}$
so suppose
$\forall j, 1 \le j \le n, \pi_j(a) = \pi_j(b), \tag{29}$
then
$\forall j, 1 \le j \le n, \pi_j(a - b) = \pi_j(a) - \pi_j(b) = 0, \tag{30}$
whence
$\forall j, 1 \le j \le n, \iota_j \pi_j(a - b) = 0; \tag{31}$
via (17), this leads to
$\forall j, 1 \le j \le n, a_j -b_j = (a - b)_j = 0, \tag{32}$
that is,
$\forall j, 1 \le j \le n, a_j = b_j, \tag{33}$
which is manifestly equivalent to $a = b$. This proves
$[\forall j, 1 \le j \le n, \pi_j(a) = \pi_j(b)]\Longrightarrow [a = b], \tag{34}$
and so we see that (27) binds. End of Proof of Fact.
We use this Fact to show
$\mathbf 1_P = \displaystyle \sum_{k = 1}^n e_k; \tag{35}$
in the light of (20) we need to evaluate $\pi_j(\sum_1^k e_k)$; we find
$\displaystyle \pi_j(\sum_{k = 1}^n e_k) = \sum_{k = 1}^n \pi_j(e_k) = \sum_{k = 1}^n \pi_j \iota_k(\mathbf 1_k) = \sum_{k = 1, k \ne j}^n \pi_j \iota_k(\mathbf 1_k) + \pi_j \iota_j(\mathbf 1_j), \tag{36}$
and by (16),
$\pi_j \iota_j(\mathbf 1_j) = \mathbf I_j(\mathbf 1_j) = \mathbf 1_j, \tag{37}$
whereas, for $j \ne k$,
$\pi_j \iota_k(\mathbf 1_k) = 0 \tag{38}$
in accord with (17); thus we have
$\displaystyle \pi_j(\sum_{k = 1}^n e_k) = \mathbf 1_j = \pi_j(\mathbf 1_P) \tag{39}$
for every $j$, $1 \le j \le n$; so in the light of our proven Fact, we have
$\mathbf 1_P = \displaystyle \sum_1^n e_k, \tag{40}$
and it remains to show that
$e_i e_j = 0, \; i \ne j; \tag{41}$
now,
$\pi_k(e_i e_j) = \pi_k(e_i)\pi_k(e_j) = \pi_k \iota_i(\mathbf 1_i) \pi_k \iota_j(\mathbf 1_j) = 0,\; 1 \le k \le n, \tag{42}$
since we have established in (38) that $\pi_k \iota_i = 0$ for $k \ne i$, and since $i \ne j$ at most one of $k = i$ or $k = j$ can hold. Thus
$\pi_k(e_i e_j) = \pi_k(0), \; 1 \le k \le n, \tag{43}$
and we may now once again invoke our Fact to affirm that
$e_ie_j = 0, \; i \ne j. \tag{44}$
We have thus shown the existence of $n$ orthogonal, non-zero idempotents which satisfy (40) in the ring $P = \prod_1^n A_i$; and hence in our original ring $A$ itself, since $f^{-1}: P \to A$ is an isomorphism.