Let $\mathbb{A}$ be a commutative $f$-algebra with unit. The sets of all ideals in $\mathbb{A}$ and all intersections of maximal ideals in $\mathbb{A}$ are denoted by $\mathfrak{I}(\mathbb{A})$ and $\mathfrak{IM}% (\mathbb{A})$, respectively. Whenever $\mathfrak{a}% \in\mathfrak{I}(\mathbb{A})$, we say that $\mathbb{A}$ is polynomially $\mathfrak{a}$-ideal if, for every $f\in\mathbb{A}$ with $p(f)\in\mathfrak{a}$ for some non-zero polynomial $p(x)$, there is an $f_{0}\in\mathfrak{a}$ such that $p(f+f_{0})=0$. We prove that if $\mathbb{A}$ is bounded inversion closed and $\mathfrak{a}\in\mathfrak{IM}(\mathbb{A})$, then $\mathbb{A}$ is polynomially $\mathfrak{a}$-ideal if and only if idempotents lift modulo $\mathfrak{a}$. This fact is based upon a systematic study of idempotent elements of an $f$-algebra. As a consequence, we show that, if $X$ is a Tychonoff space, then $C(X)$ is polynomially $\mathfrak{a}$-ideal for all $\mathfrak{a}\in\mathfrak{I}(C(X))$ if and only if $X$ is a $P$-space. Moreover, we prove that $C(X)$ is polynomially $\mathfrak{a}$-ideal for all $\mathfrak{a}\in\mathfrak{IM}(C(X))$ if and only if $X$ is strongly zero-dimensional. It turns out that this extends a theorem by Miers, namely, if $X$ is a compact Hausdorff space, then $C(X)$ is polynomially $\mathfrak{a}$-ideal for every uniformly closed ideal $\mathfrak{a}$ in $C(X)$ if and only if $X$ is totally disconnected.