Proof (Eisenstein's criterion)

Suppose $f = gh$ with $g = r_0 + r_1 X + \ldots + r_k X^k$ and $h=s_0 + s_1 X + \ldots + s_l X^l$ and $r_k, s_l \neq 0$. Since $R$ is an integral domain, $n=k+l$.

Since $p\not\mid a_n = r_k s_l$ and $p$ is prime, $p\not\mid r_k$ and $p\not\mid s_l$. Moreover since $p\mid a_0$ but $p^2\not\mid a_0 = r_0 s_0$, $p$ divides exactly one of $r_0$ and $s_0$. WLOG assume $p\mid r_0$ but $p\not\mid s_0$.

Let $j=1,\ldots,k$ be minimal such that $p\not\mid r_j$ (which exists as $p\not\mid r_k$ and $\geq 1$ as $p\mid r_0$). Note that $$ \begin{align*} a_j = \underbrace{r_0 s_j + r_1 s_{j-1} + \ldots + r_{j-1} s_1}_{\text{divisible by $p$}} + r_j s_0. \end{align*} $$ Since $p\mid r_0, \ldots, r_{j-1}$, $p\not\mid r_j$ and $p\not\mid s_0$, we have $p\not\mid a_j$. This means $j = n$, and thus $k=n$ and $l=0$.

Finally because $f$ is primitive, $h$ must be a unit. Therefore $f$ cannot be factorised into non-units.