4. Find all functions $f: \mathbf{Z} \rightarrow \mathbf{Z}$, such that for all integers $m, n$, we have
$$
\begin{array}{r}
f(f(m)+n)+f(m) \\
=f(n)+f(3 m)+2014
\end{array}
$$
4. Let the function $f$ satisfy equation (1).

Let $C=1007$, and define the function $g: \mathbf{Z} \rightarrow \mathbf{Z}$ such that for all $m \in \mathbf{Z}$, we have
$$
g(m)=f(3 m)-f(m)+2 C .
$$

In particular, $g(0)=2 C$.
Thus, for all $m, n \in \mathbf{Z}$, we have
$$
f(f(m)+n)=g(m)+f(n) \text {. }
$$

By mathematical induction in two directions, we know that for all $m, n, t \in \mathbf{Z}$, we have
$$
f(t f(m)+n)=t g(m)+f(n) \text {. }
$$

Substituting $(r, 0, f(0))$ and $(0,0, f(r))$ for $(m, n, t)$, we get
$$
\begin{array}{l}
f(0) g(r)=f(f(r) f(0))-f(0) \\
=f(r) g(0) .
\end{array}
$$

If $f(0)=0$, then by $g(0)=2 C>0$, we have
$$
f(r)=0 \text {, }
$$

which contradicts equation (1).
If $f(0) \neq 0$, then $g(r)=\alpha f(r)$, where $\alpha=\frac{g(0)}{f(0)}$ is a non-zero constant.
By the definition of $g$, we have
$$
f(3 m)=(1+\alpha) f(m)-2 C,
$$

i.e., for all $m \in \mathbf{Z}$, we have
$$
f(3 m)-\beta=(1+\alpha)(f(m)-\beta),
$$

where $\beta=\frac{2 C}{\alpha}$.
Using mathematical induction on $k$, we know that for all integers $k (k \geqslant 0), m$, we have
$$
f\left(3^{k} m\right)-\beta=(1+\alpha)^{k}(f(m)-\beta) .
$$

Since $3 \times 2014$, by equation (1), there exists $a \in \mathbf{Z}$ such that $d=f(a)$ is not divisible by 3.
By equation (2), we have
$$
f(n+t d)=f(n)+t g(a)=f(n)+\alpha t f(a),
$$

i.e., for all $n, t \in \mathbf{Z}$, we have
$$
f(n+t d)=f(n)+\alpha t d .
$$

Since $(3, d)=1$, by Euler's theorem, there exists $k$ (we can take $k=\varphi(|d|)$) such that
$$
d \mid\left(3^{k}-1\right) \text {. }
$$

For each $m \in \mathbf{Z}$, by equation (5), we have
$$
f\left(3^{k} m\right)=f(m)+\alpha\left(3^{k}-1\right) m \text {. }
$$

Thus, equation (4) becomes
$$
\left[(1+\alpha)^{k}-1\right](f(m)-\beta)=\alpha\left(3^{k}-1\right) m \text {. }
$$

Since $\alpha \neq 0$, for $m \neq 0$, the right-hand side of equation (6) is not zero.

Therefore, the first factor on the left-hand side of equation (6) is also not zero. Hence, $f(m)=\frac{\alpha\left(3^{k}-1\right) m}{(1+\alpha)^{k}-1}+\beta$.
This indicates that $f$ is a linear function.
Let $f(m)=A m+\beta (m \in \mathbf{Z}$, constant $A \in \mathbf{Q})$.
Substituting this into equation (1), we know that for all $m \in \mathbf{Z}$, we have
$$
\left(A^{2}-2 A\right) m+(A \beta-2 C)=0
$$
$\Leftrightarrow A^{2}=2 A$, and $A \beta=2 C$.
The first equation is equivalent to $A \in\{0,2\}$.
Since $C \neq 0$, by the second equation, we have
$$
A=2, \beta=C \text {. }
$$

Thus, the function that satisfies the conditions is
$$
f(n)=2 n+1007
$$