The result you want to prove is known as Kaplansky's criterion for unique factorization domains (UFD). To prove it you have to consider the set $S$ consisting of the units of $R$ together with (finite) products of all the prime elements of $R$.
Basically the idea is to show that $S=R\setminus \{0\}$. This can be done using the following result:
Lemma: $S$ is a saturated multiplicatively closed set.
Proof: If $x, y\in S$, then we can write both $x$ and $y$ as product of primes, so $xy$ can be also written as product of primes. This shows that $S$ is a multiplicatively closed set.
Now, to prove that $S$ is saturated we have to show that if $x\in S$, then every divisor of $x$ is in $S$ too. If we write $x=up_1\cdots p_n$, where $u$ is an unit and the $p_i$'s are prime, then it can be shown by induction on $n$ that every divisor of $x$ is in $S$. I let you to do this proof by induction.
Now, we argue by contradiction assuming that there is a nonzero element $a\in R$ such that $a\notin S$, so the ideal generated by $a$, $\langle a\rangle$, is disjoint from $S$, i.e., $S\cap \langle a\rangle=\emptyset$, because if there were some $ra\in S$, then $a$ would be in $S$ (because $a\mid ra$ and $S$ is saturated by the lemma above), contradicting our hypothesis that $a\notin S$.
Therefore the set $A=\{I\; \text{nonzero ideal of}\; R:I\cap S=\emptyset\}$ is non-empty and then by Zorn's Lemma $A$ has a maximal element $P$ such that $P$ is not only an ideal, but in fact a prime ideal. By our general hypothesis $P$ contains a prime element, let's say $p$, i.e., $p\in P$, but by the definition of $S$ is clear that $p\in S$, so $p\in P\cap S$, which contradicts $P\cap S=\emptyset$. This contradiction comes from our assumption that $a\notin S$.
Hence every nonzero $a\in R$ belongs to $S$, i.e., $S=R\setminus \{0\}$ and this means that every nonzero, nonunit element of $R$ is expressible as a product of primes.
elaborateahem insightful that it may have gone unappreciated. – rschwieb Feb 09 '17 at 05:11