As **Pasten** suggested in the comments, the key tool here is Siegel's theorem,
and this was already done by Silverman, see "Theorem A" in

Joseph H. Silverman:
Integer points, Diophantine approximation, and iteration of rational maps,
*Duke Math. J.* **71** (1993) #3, 793--829.

**Proposition.** *Fix a rational function $f \in {\bf Q}(x)$,
and some $n_0 \in {\bf Q} \cup \{\infty\}$;
for $i=1,2,3,\ldots$, define $n_i$ inductively by $n_i = f(n_{i-1})$.
Then if $n_i \in \bf Z$ for infinitely many $i$, then either*

*(i) $\{n_i\}$ is periodic, or*

*(ii) $f$ has the form $f(x) = c + a/(x-c)^m$ for some $a,c \in \bf Q$
(with $a \neq 0$) and $m>1$, or*

*(iii) $f$ is a polynomial.*

In each case it is also possible to have $n_i \notin \bf Z$
for infinitely many $i$. Note that case (ii) contains **Kimball**'s example,
and is in fact equivalent to it under conjugation by $x \mapsto x+c$.

The point is that if $\{n_i\}$ is not periodic then for each $j=1,2,3,\ldots$
the $j$-th iterate $f^j$ satisfies $f^j(x) \in \bf Z$
for infinitely many distinct $x \in \bf Q$, whence $f^j$ has
at most two distinct poles By Siegel's theorem on integral points.
Silverman uses this to show that $f^2$ is polynomial, and thence that
$f$ is either polynomial or of the form exhibited in (ii) by citing
a result from

A. Beardon: *Iteration of Rational Functions* (GTM **132**),
New York: Springer 1991

($\S$4.1), which he describes as "elementary" and "well-known",
and also proves as Proposition 1.1 of his paper (pages 798--799).

A simple example of a polynomial whose iterates can take both
integer and non-integer values is $f(x) = x + a$ for non-integral
$a \in \bf Q$, say $f(x) = x+\frac12$. More complicated examples such as
$f(x) = 2x^2 + \frac12$ can be obtained as $f(x) = P(cx)/c$ for
suitable polynomials $P$ of degree $2$ or greater (here $P(x) = x^2+1$
and $c=2$). One can even construct examples such as $f(x) = x^2 + \frac{x}{2}$
for which it is probably true that the iterates of every integer include
both integers and non-integers but this is very hard to prove
(this example encodes the behavior of the parity of iterates of
$x \mapsto (x^2+x)/2$).