The formal completion of $X$ along $Z$ is always isomorphic to that of the normal bundle $N_{Z \subset X}$ along its zero section if $X= \mathrm{Spec}(A)$ and $Z = \mathrm{Spec}(A/I)$ are smooth and affine over some base $k$. If the affineness or smoothness assumption is dropped, it is easy to give counterexamples.
It's easier to work in the world of algebra, so I will show that there exists an isomorphism of $k$-algebras
$$\mathrm{Sym}_{A/I}(I/I^2) \to \widehat{A}$$$$\widehat{\mathrm{Sym}}_{A/I}(I/I^2) \to \widehat{A}$$
compatible with the projection down to $A/I$. Here $\widehat{A}$ is the $I$-adic completion of $A$, and $\widehat{\mathrm{Sym}}_{A/I}(I/I^2)$ is the completion of the symmetric algebra $\mathrm{Sym}_{A/I}(I/I^2)$ along the augmentation ideal.
By the infinitesimal criterion for smoothness, one can find a compatible system of $k$-algebra maps $\epsilon_n:A/I \to A/I^n$ lifting the projection $A/I^n \to A/I$. In the limit, we obtain a $k$-algebra map $\epsilon:A/I \to \widehat{A}$ lifting the projection $\widehat{A} \to A/I$. Using $\epsilon$, we view $\widehat{A}$ and each quotient $A/I^n$ as $A/I$-algebras.
Now the $A/I$-module $I/I^2$ is a projective module as $X$ and $Z$ are smooth. There is an obvious $A/I$-module map $I/I^2 \to A/I^2 \simeq \widehat{A}/I\widehat{A}^2$. By projectivity, one can find an $A/I$-module map $I/I^2 \to \widehat{A}$ lifting the previous one. By the universal property of the symmetric algebra, this extends to an $A/I$-algebra map $\mathrm{Sym}_{A/I}(I/I^2) \to \widehat{A}$. As both sides are augmented over $A/I$, this naturally extends to an $A/I$-algebra map $\widehat{\mathrm{Sym}}_{A/I}(I/I^2) \to \widehat{A}$; by filtering both sides suitably, one can check that this is an isomorphism.