Euclid's Lemma in a PID: irreducibles are prime: $ \pi\mid ab\Rightarrow \pi\mid a\,$ or $\pi\mid b$ I am studying ring theory and I am having a hard time understanding a part of a proof of a certain theorem. Note that in my lecture notes, a ring is by definition commutative with $1$. Let $R$ be a ring, then the set of units of $R$ is denoted by $R^*$.
Consider the following theorem:

Let $R$ be a principal ideal domain (PID) and $\pi\in R$ irreducible. For any $a,b\in R$ with $\pi|ab$ we have $\pi|a$ or $\pi|b$.

The following is the first part of the proof from my lecture notes:

Consider the ideal $(a,\pi)$. Since $R$ is a PID this ideal is generated by a single element, which we call g. Note that $g|\pi$. Hence either $g$ is a unit, or $g=\epsilon\pi$ with $\epsilon\in R^*$. In the second case, since $g|a$ we also get $\pi|a$ and our assertion is proven.

The second part of the proof covers the case in which $g$ is a unit; I understand what's going on there (under the assumption that $g$ is indeed a unit) so I've omitted it. Please note that this is the proof word by word, i.e. I have quoted it from my lecture notes.
First of all, is it true that, since $(g)=(a,\pi)$ we have $\{rg\ |\ r\in R\}=\{r_1a+r_2\pi\ |\ r_1,r_2\in R\}$ and by choosing $r_1=0$ and $r_2=1$ we have $rg=\pi$ for some $r\in R$, thus $g|\pi$? If this is true, then by similar reasoning one can proof that $g|a$ (which is stated in the last sentence of the proof).
Next, the proof says that $g$ is either a unit or $g=\epsilon\pi$ for some unit $\epsilon$. By definition, we see from the factorisation above that either $g$ or $r$ is a unit. The first case corresponds to the statement in the proof that $g$ can be a unit. But if $g$ is not a unit, why is $g=\pi\epsilon$ for some unit $\epsilon$?
Lastly, how does $\pi|a$ follow from all that has been said in the proof?
EDIT:
As requested by a user in the comments, here is the second part of the proof in my lecture notes, along with the first one for easy reading:

Consider the ideal $(a,\pi)$. Since $R$ is a PID this ideal is generated by a single element, which we call g. Note that $g|\pi$. Hence either $g$ is a unit, or $g=\epsilon\pi$ with $\epsilon\in R^*$. In the second case, since $g|a$ we also get $\pi|a$ and our assertion is proven.
Now suppose  that $g$ is a unit and hence $(a,\pi)=R$. In this case there exist $x,y\in R$ such that $ax+\pi y=1$. Multiply by $b$ to get $abx+\pi by=b$. Both terms on the left are divisible by $\pi$. Hence the sum $b$ is also divisible by $\pi$ which proves our theorem.

 A: The proof is an exact PID translation of a well-known proof that an irreducible integer $p$ is prime (by a version of of Euclid's Lemma). Highlighting this analogy greatly clarifies the conceptual essence of the matter (and answers your question and then some).
Theorem $ $ irreducible $\,p\mid ab\,\Rightarrow\, p\mid a\ $ or $\ p\mid b\ $ in $\Bbb Z,\,$ since, with $\,(x,y) := \gcd(x,y)$
$(a,p) = p\ $ or $\,1,\ $  by $\,(a,p)\mid p\,$ and $\,p\,$ is $\rm\color{#06f}{irreducible}$
$(a,p) = p\ \Rightarrow\ p \mid a.\ $ In the other case, employing $\,\rm\color{#c00}{DL}$ = GCD Distributive Law
$(a,p) = 1\ \Rightarrow\ p\mid b,\, \ $ by $\,p\mid ab,pb\,\Rightarrow\,p\mid (ab,pb)\overset{\rm\color{#c00}{DL}}= (a,p)b = b.$ $\ \ \small\bf QED$
For principal ideals $\ \rm\color{#0a0}{contains} = \color{#c00}{divides}$, $ $ i.e.  $\,(a)\supset (b)\!\iff\! a\mid b,\,$ so translating with this:
Theorem $ $ irreducible $\,p\mid ab\,\Rightarrow\, p\mid a\ $ or $\ p\mid b\ $ in a PID, since, with $\,(x,y) := xR\!+\!yR\,$
$(a,p) = (p)\ $ or $\,(1),\ $  by $\,(a,p)\supseteq (p)\,$ and $\,p\ \rm\color{#06f}{irreducible}$ $\Rightarrow(p)\ \rm\color{#06f}{maximal}$ $ $ [proof below]
$(a,p) = (p)\ \Rightarrow\ (p) \supseteq (a)\,\Rightarrow\,p\mid a$
$(a,p) = (1)\ \Rightarrow\ p\mid b,\, \ $ by $\ (p)\supseteq (ab),(pb)\,\Rightarrow\,(p)\supseteq (ab,pb) = (a,p)b = (b).$ $\ \ \small\bf QED$
Note: above we used that, in a PID, since $\ \rm\color{#0a0}{contains} = \color{#c00}{divides}$, we have
$\qquad\qquad\begin{eqnarray} (p)\,\text{ is $\rm\color{#06f}{maximal}$} 
&\iff&\!\!\ (p)\, \text{ has no proper } \,{\rm\color{#0a0}{container}}\,\ (d)\\
&\iff&\  p\ \ \text{ has no proper}\,\ {\rm\color{#c00}{divisor}}\,\ d\\
&\iff&\  p\ \ \text{ is $\rm\color{#06f}{irreducible}$}\\
\end{eqnarray}$
Remark $ $ Further, notice that $\,(a,b) = (d)\iff d\,$ is a gcd of $a,b,\,$ since
$$ c\mid a,b\iff (c)\supseteq (a),(b)\iff (c)\supseteq (a,b)\!=\!(d)\iff c\mid d\quad$$
therefore $\,d\,$ is a gcd of $\,a,b\,$ since it satisfies the universal definition of a GCD.
Hence in a PID, $\,(a,b)\,$ can be read as both an ideal and a gcd, facilitating said analogy.
In fact, the above proof generalizes to show that any maximal ideal is prime  - see Euclid's Lemma in Bezout form, gcd form and ideal form, which highlights the role the various distributive laws play in the Bezout, gcd, and ideal forms of the proof.
More generally, any ideal maximal in the complement of a monoid is prime - see here.
When first learning about PIDs, it will be very instructive to view them as generalization of $\,\Bbb Z\,$ and, as above, translate well-know proofs from $\,\Bbb Z\,$ to PID language.
A: If $gr=\pi$, and $g$ is not a unit, then $r$ is (by definition of $\pi$ being irreducible), hence we can write $g=r^{-1}\pi$, so your $\varepsilon$ is nothing else than $r^{-1}$.
Also since $g$ divides $a$, any associated element (multiple of $g$ by a unit) does  too, in particular $\pi$. Indeed, since $a=a_1g$, we deduce $a=a_1r(r^{-1}g)=a_1r\pi$.
