Let $m_1, \ldots, m_n$ be generators of $M$ and define an $R$-module homomorphism $f: R^n \rightarrow M$ by $(r_1, \ldots, r_n) \mapsto r_1m_1 + \ldots + r_nm_n$. Since the $m_i$ generate $M$, $f$ is surjective. Therefore $M \cong R^n/\ker f$.
Recall that an $R$-module is called Noetherian if every submodule is finitely generated. A ring $R$ is called Noetherian if it is Noetherian as a module over itself, which is equivalent to all ideals being finitely generated.
In our case, since $R$ is a PID it is automatically Noetherian (every ideal is generated by a single element, so is certainly finitely generated). Therefore finitely generated $R$-modules are Noetherian. In particular, $R^n$ is Noetherian, so the submodule $\ker f$ is finitely generated.
Pick generators $k_1, \ldots, k_m$ for $\ker f$ and define a homomorphism $g: R^m \rightarrow R^n$ by $(r_1, \ldots, r_m) \mapsto r_1k_2 + \ldots + r_mk_m$. Then $M \cong R^n / \ker f \cong R^n / \mathrm{im} \ g$. Writing $g$ in $n \times m$ Smith normal form with diagonal entries $a_1, \ldots, a_n$ as you suggest (where $a_{m+1}, \ldots, a_n$ are defined to be $0$ if $m<n$), we see that $M \cong R/(a_1) \oplus \ldots \oplus R/(a_n)$. Since $a_1 | \ldots | a_n$ we have $(a_1) \supset \ldots \supset (a_n)$. This proves existence.
For uniqueness, the cleanest way is with tensor products. Since $R$ is a PID we can take prime factorisations of the $a_i$. For each prime $p \in R$, the ideal $(p)$ is maximal, so $K :=R/(p)$ is a field, and the number of $a_j$ divisible by $p$ is simply the dimension of $K \otimes_R M$ as a $K$-vector space. More generally, the number of $a_j$ divisible by $p^d$ is the dimension of $K \otimes_R (p^{d-1}M)$. The dimensions of the $K \otimes_R (p^{d-1}M)$ are intrinsic to $M$, and using the fact that $a_1 | \ldots | a_m$ we can reconstruct the $a_j$ from them. (This won't detect any $a_i$ equal to $1$ but we can just delete these since $R/(1)=0$.)
Best Answer
Abelian groups = $\mathbb{Z}$-modules, so it is a special case of module over PID.
To answer your second concern in the comments, there is one thing that the proof of the theorem applies to submodules. As an immediate corollary, you obtain that those are also finitely generated, and in fact by at most as many elements as the original. The main idea of the proof is that every submodule has a very special basis. Namely, if $N\leq M$ is a submodule, then it is possible to pick a basis $b_1, \ldots, b_n$ in $M$ and elements $r_1, \ldots, r_n$ in the PID such that $r_1b_1, \ldots, r_nb_b$ is a basis of $N$, and $r_1\mid r_2\mid\cdots\mid r_n$. Clearly if the index is 17, then $r_1=\cdots=r_4=1$ and $r_5=17$. If you show that four elements of the original basis must be generated, and $17$ times the fifth also, then you obtain that there are five such subgroups.