Let $(R,m)$ be a local ring of Krull dimension $0$ such that the residue field $R/m$ is finite ; then is it true that $\exists f(X) \in R[X]$ such that $f(R)=\{f(r) : r \in R \}= \{0,1\}$ ?
If we also assume that $m^n=0$ for some $n>0$ i.e. that say $m$ is a nilpotent ideal , then I can show the claim is true .
Let $k$ be a finite field and let $R=k[x_1,x_2,x_3,\dots]/(x_1^2,x_2^4,x_3^8,\dots)$. Then $R$ satisfies all your hypotheses. However, if $f(X)\in R[X]$, then $f$ involves only finitely many of the variables $x_i$. Let $n$ be such that the variable $x_n$ does not appear in $f$ and $\deg f<2^n$. Then since the only relation involving $x_n$ is $x_n^{2^n}$, $f(x_n)$ can only be equal to $0$ or $1$ if it is a constant polynomial. So there is no $f$ such that $f(x_n)\in \{0,1\}$ for all $n$ and both values $0$ and $1$ are in the image of $f$.