In fact, one can prove the following theorem:
Thm. Let $A$ be a commutative ring with 1. Then $X$ is irreducible in $A[X]$ if and only if $A$ has no nontrivial idempotent elements (nontrivial meaning: different from $0$ and $1$)
Proof. I will prove in fact that $X$ is reducible if and only if $A$ has a nontrivial idempotent.
Assume that $e\in A$ is an idempotent different from $0$ and $1$. Then the polynomials $(1-e)X+e$ and $eX+(1-e)$ are nonzero, non invertible (otherwise their constant terms would be invertible, which would imply that $e=0$ or $1$, since $e(1-e)=0$). However, $((1-e)X+e)(eX+(1-e))=X$, so $X$ is
reducible.
Assume now that $X$ is reducible. Notice that it is nonzero, and non invertible (since its constant term is not invertible). Hence $X=RS,$ where $R$ and $S$ are not invertible
Write $R=a+XP,S=b+XQ.$ We then have $X=ab+(aQ+bP)X+X^2PQ$.
Evaluation at $0$ yields $ab=0$. Therefore $X=(aQ+bP)X+X^2PQ$. Sicne multiplication by $X$ is injective, we get $$1=aQ+bP+XPQ.$$ Set $v=P(0)$ et $u=Q(0)$. Evaluation at $0$ yields $au+bv=1$.
Set $e=au$. We have $$e^2=au (1-bv)=au-abuv=au=e,$$
hence $e$ is an idempotent.Assume that $e=0$. Then, $bv=1$, so $b$ is invertible and consequently $a=0.$
We then have $X=XPS$. Since multiplication by $X$ isinjective, we obtain $1=PS$, so $S$ is invertible, contradiction. Hence, $e\neq 0$.
Similarly if $e=1$, then $au=1$ and we obtain this time that $R$ is invertible. Conclusion: $e$ is a nontrivial idempotent of $A$.