TITLE: Idempotent polynomials
QUESTION [11 upvotes]: Let $R$ be a commutative ring with identity and let $f \in R[x]$. There are well known characterizations for $f$ to be a nilpotent element of $R[x]$ or to have  a multiplicative  inverse in $R[x]$. Is there any characterization for idempotent elements in $R[x]$ ?

REPLY [4 votes]: Based on @user30230's great answer, but avoiding induction: Let $f=a+gx$, with $a\in R$ and $g\in R[x]$. Then $f=f^2$ yields $a+gx=a^2+2agx+g^2x^2$, so $a=a^2$ and $(1-2a)gx=g^2x^2$. Since $(1-2a)^2=1$, then $(1-2a)gx=\bigl[(1-2a)gx\bigr]^2$, so $(1-2a)gx=\bigl[(1-2a)g\bigr]^nx^n$ for all $n\geq1$. Thus, every power of $x$ divides $(1-2a)gx$, which forces $(1-2a)gx=0$. As $(1-2a)x$ is regular, it follows that $g=0$. Note that the argument also works for formal power series.