Example 2 Find all integer solutions to the equation $3 x+7 y+16 z=40$.

Translate the above text into English, please keep the original text's line breaks and format, and output the translation result directly.
Since $(3,7)=1$, the equation has a solution.
Let $3 x+7 y=t$, this can be regarded as a linear Diophantine equation in two variables, its general solution is
$$x=-2 t+7 u, y=t-3 u$$

On the other hand, the general solution of $t+16 z=40$ is
$$t=40-16 v, z=v$$

Therefore, all solutions of the original equation are
$$x=-80+32 v+7 u, y=40-16 v-3 u, z=v$$

where $u, v$ are arbitrary integers.