I found on the Web and, also on mathstack, several examples and I decided to write an answer.
Example of ring where the gcd of two elements doesn't exist:
Consider the ring $\Bbb Z[\sqrt{-d}]=\{a+bi\sqrt{-d} : a,b\in \Bbb Z\}$, $d\ge 3$ ($d$ free-square). Then in this paper D. Khurana has proved that:
Let $a$ be any rational integer such that $a\equiv d\quad (mod\quad 2)$ and let $a^2 + d = 2q$. Then the elements $2q$ and $(a+ i\sqrt{d})q$ do not have a $GCD$.
Two examples of ring where the lcm of two elements doesn’t exist:
I use the following theorem:
Let $D$ be a domain and $a,b\in D$.
Then, $\text{lcm}(a,b)$ exists if and only if for all $r\in D\setminus\{0\}$, $\gcd(ra,rb)$ exists.
$1)$Consider the ring $\Bbb Z[\sqrt{-d}]=\{a+bi\sqrt{-d} : a,b\in \Bbb Z\}$, $d\ge 3$ ($d$ free-square); and a rational integer $a$ such that $a\equiv d$ $(mod\quad 2)$, then $lcm(2,a+i\sqrt{d})$ doesn't exist. Indeed this follows from the previous theorem. Note that $GCD(2,a+i\sqrt{d})=1$.
$2)$ let $R$ be the subring of $\Bbb Z[x]$ consisting of the polynomials $\sum_i c_ix^i$ such that $c1$ is an even number. If we consider $p_1(x)=2$ and $p_2(x)=2x$, $lcm(p_1, p_2)$ doesn't exist.
You are almost there. The first steps are as you described. Then just note that $R^\times \simeq \oplus_{i = 1}^n (\mathbb{F}_p[x]/(a_i^{e_i}))^\times$, so the number of invertible elements of $R$ is simply the product of the numbers of invertible elements of each $\mathbb{F}_p[x]/(a_i^{e_i})$.
Thus the question is reduced to finding the cardinal of $(\mathbb{F}_p[x]/(a^e))^\times$, where $a\in\mathbb{F}_p[x]$ is an irreducible polynomial. Let $d = \deg a$ be the degree of $a$.
Note that there is a surjective homomorphism of rings $\mathbb{F}_p[x]/(a^e) \rightarrow \mathbb{F}_p[x]/(a) = \mathbb{F}_{p^d}$, where $\mathbb{F}_{p^d}$ is the unique extension of $\mathbb{F}_p$ of degree $d$.
Taking units gives us a homomorphism of groups $$\pi:(\mathbb{F}_p[x]/(a^e))^\times \rightarrow \mathbb{F}_{p^d}^\times.$$
Now it is an easy exercise to show that $\pi$ is surjective, and the kernel $K$ of $\pi$ is equal to $(1 + a\mathbb{F}_p[x])/(a^e)$, which via the map $t \mapsto t - 1$ is in bijection with $a\mathbb{F}_p[x]/(a^e)$, which is a vector space over $\mathbb{F}_{p^d}$ of dimension $e - 1$.
Therefore, we have $\#(\mathbb{F}_p[x]/(a^e))^\times = \#K \cdot \#\mathbb{F}_{p^d}^\times = p^{d(e - 1)}\cdot(p^d - 1) = p^{de}(1 - \frac{1}{p^d})$.
You may compare this to the case of $(\mathbb{Z}/(p^e))^\times$.
Best Answer
By the universal $\rm\color{#c00}{def}$inition of the gcd, If $\,d,d'$ are both gcds of all of the $\,a_i\,$ then $\,c\mid d\!\!\!\overset{\rm\ \ \color{#c00}{def}}\iff\! c\mid a_1,\ldots ,a_n\!\!\!\overset{\rm\ \ \color{#c00}{def}}\iff\! c\mid d',\,$ so for $\,c=d\,$ we get $\,d\mid d'$ and for $\,c = d'\,$ we get $\,d'\mid d,\,$ so $\,d,d'$ divide each other so are associate (thus $\,d' = u d\,$ for some unit $u,\,$ being in a domain).