On polynomials over finite ring Let $R$ be a finite commutative ring with unity ; then does there exist a non-empty proper subset $A \subseteq R$ and $f(X) \in R[X]$ such that $f(r)=1 , \forall r \in A$ and $f(r)=0 , \forall r \notin A$ ?

Such an $f$ exists iff $R$ is local.
First, suppose $R$ is local.  Since $R$ is finite, its unique maximal ideal is the nilradical, so every element of $R$ is either nilpotent or a unit.  There is then some $n$ such that $r^n=0$ for every nilpotent $n$ and $r^n=1$ for every unit $r$.  You can then take $f(X)=X^n$.
Now suppose $R$ is not local.  Equivalently, this means either $R$ is the zero ring (in which case $R$ has no nonempty proper subsets) or $R$ is isomorphic to a direct product $S\times T$ of two nontrivial rings $S$ and $T$.  Then given any $f\in R[X]$, consider its images $f_S\in S[X]$ and $f_T\in T[X]$.  Note that the set of values which $f$ takes is the product of the set of values $f_S$ takes and the set of values $f_T$ takes.  So the set of values $f$ takes must be a "rectangle" in the product $S\times T$.  But since $S$ and $T$ both have more than one element, the set $\{0,1\}=\{(0,0),(1,1)\}\subset R$ is not a rectangle, so it cannot be the set of values taken by any polynomial.
