I suspect it is impossible to find such an $f$, but I can see one way it might be possible to as well.
If it is possible to construct two sets $A$ and $B$ which partition the non-negative reals such that $A \cap [0,a)$ and $B \cap [0,a)$ both have measure $a/2$ for any positive real $a$, then take $f^{-1}(1) = A$, $f^{-1}(-1) = B$. We would have $\int_0^a{f(x)\,dx}=0$ for all $a$ and $\lim_{a \to \infty}\int_0^a{f(x)\,dx}=0$.
It is possible as an improper integral. Fix a conditionally convergent series $\sum_{n=1}^{\infty} a_n$, and let $T_n = \sum_{k=1}^{n} |a_k|$. Then define $f$ as
$$ f(x) = \operatorname{sgn}(a_n) \qquad\text{whenever}\quad x \in [T_{n-1}, T_n). $$
Then it follows that
$$ \int_{T_{k-1}}^{T_k} f(t) \, \mathrm{d}t = \int_{T_{k-1}}^{T_k} \operatorname{sgn}(a_k) \, \mathrm{d}t = \operatorname{sgn}(a_k)(T_k - T_{k-1}) = a_k. $$
So, whenever $x \in [T_n, T_{n+1})$, we get
\begin{align*} \left| \int_{0}^{x} f(t) \, \mathrm{d}t - \sum_{k=1}^{n} a_k \right| = \left| \int_{T_n}^{x} f(t) \, \mathrm{d}t \right| \leq a_{n+1}, \end{align*}
and this converges to $0$ as $n \to \infty$. Therefore,
$$ \int_{0}^{\infty} f(t) \, \mathrm{d}t = \sum_{k=1}^{\infty} a_k. $$