Finding invertible polynomials in polynomial ring $\mathbb{Z}_{n}[x]$ 
Is there a method to find the units in $\mathbb{Z}_{n}[x]$? 

For instance, take $\mathbb{Z}_{4}$. How do we find all invertible polynomials in $\mathbb{Z}_{4}[x]$? Clearly $2x+1$ is one. What about the others? Is there any method?

Lemma 1. Let $R$ be a commutative ring. If $u$ is a unit and $a$ is nilpotent, then $u+a$ is a unit.
Proof. It suffices to show that $1-a$ is a unit when $a$ is nilpotent. If $a^n=0$ with $n\gt 0$, then
$$(1-a)(1+a+a^2+\cdots+a^{n-1}) = 1 - a^n = 1.$$
QED
Lemma 2. If $R$ is a ring, and $a$ is nilpotent in $R$, then $ax^i$ is nilpotent in $R[x]$.
Proof. Let $n\gt 0$ be such that $a^n=0$. Then $(ax^i)^n = a^nx^{ni}=0$. QED
Lemma 3. Let $R$ be a commutative ring. Then
$$\bigcap\{ \mathfrak{p}\mid \mathfrak{p}\text{ is a prime ideal of }R\} = \{a\in R\mid a\text{ is nilpotent}\}.$$
Proof. If $a$ is nilpotent, then $a^n = 0\in\mathfrak{p}$ for some $n\gt 0$ and all prime ideals $\mathfrak{p}$, and $a^n\in\mathfrak{p}$ implies $a\in\mathfrak{p}$.
Conversely, if $a$ is not nilpotent, then the set of ideals that do not contain any positive power of $a$ is nonempty (it contains $(0)$) and closed under increasing unions, so by Zorn's Lemma it contains a maximal element $\mathfrak{m}$. If $x,y\notin\mathfrak{m}$, then the ideals $(x)+\mathfrak{m}$ and $(y)+\mathfrak{m}$ strictly contain $\mathfrak{m}$, so there exists positive integers $m$ and $n$ such that $a^m\in (x)+\mathfrak{m}$ and $a^n\in (y)+\mathfrak{m}$. Then $a^{m+n}\in (xy)+\mathfrak{m}$, so $xy\notin\mathfrak{m}$. Thus, $\mathfrak{m}$ is prime, so $a$ is not in the intersection of all prime ideals of $R$. QED
Theorem. Let $R$ be a commutative ring. Then
$$p(x) = a_0 + a_1x + \cdots + a_nx^n\in R[x]$$
is a unit in $R[x]$ if and only if $a_0$ is a unit of $R$, and each $a_i$, $i\gt 0$, is nilpotent. 
Proof. Suppose $a_0$ is a unit and each $a_i$ is nilpotent. Then $a_ix^i$ is nilpotent by Lemma 2, and applying Lemma 1 repeatedly we conclude that $a_0+a_1x+\cdots+a_nx^n$ is a unit in $R[x]$, as claimed.
Conversely, suppose that $p(x)$ is a unit. If $\mathfrak{p}$ is a prime ideal of $R$, then reduction modulo $\mathfrak{p}$ of $R[x]$ maps $R[x]$ to $(R/\mathfrak{p})[x]$, which is a polynomial ring over an integral domain; since the reduction map sends units to units, it follows that $\overline{p(x)}$ is a unit in $(R/\mathfrak{p})[x]$, hence $\overline{p(x)}$ is constant. Therefore, $a_i\in\mathfrak{p}$ for all $i\gt 0$.
Therefore, $a_i \in\bigcap\mathfrak{p}$, the intersection of all prime ideals of $R$. The intersection of all prime ideals of $R$ is precisely the set of nilpotent elements of $R$, which establishes the result.  QED
For $R=\mathbb{Z}_n$, let $d$ be the squarefree root of $n$ (the product of all distinct prime divisors of $n$). Then a polynomial $a_0+a_1x+\cdots+a_nx^n\in\mathbb{Z}_n[x]$ is a unit if and only if $\gcd(a_0,n)=1$, and $d|a_i$ for $i=1,\ldots,n$.  In particular if $n$ is squarefree, the only units in $\mathbb{Z}_n[x]$ are the units of $\mathbb{Z}_n$.
