Let us integrate along the contour $\Gamma$, which is the semicircle of radius $R$ described above. Let $C_R$ be the arc of the contour with radius $R$. We may say that
$\oint_{\Gamma}\frac{\cos z}{z^2+a^2}\, dz=\int_{-R}^{R}\frac{\cos x}{x^2+a^2}\, dx+\int_{C_R}\frac{\cos z}{z^2+a^2}\, dz$
Note that $\cos x = \operatorname{Re}\,(e^{ix})$. Thus
$ f(z)=\frac{\operatorname{Re}\,(e^{iz})}{z^2+a^2} = \operatorname{Re}\,\left(\frac{e^{iz}}{(z+ia)(z-ia)}\right) $
Because $f(z)$ can be written ias $g(z)e^{iaz}$ and suffices all of the conditions of Jordan's lemma, we see that the integral along the arc tends to zero when $R\to \infty$. Thus
$ \lim_{R\to\infty}\oint_{\Gamma}\frac{\cos z}{z^2+a^2}\, dz=\lim_{R\to\infty} \int_{-R}^{R}\frac{\cos x}{x^2+a^2}\, dx+0 $
To solve the LHS, we find the residues. The residue, similar to the one you found is $ b=\frac{e^{i^2a}}{ia+ia}=\frac{e^{-a}}{2ia} $
Thus
$ \displaystyle\int_{-\infty}^{\infty} \frac{\cos x}{x^{2} + a^{2}}\, dx= \lim_{R\to\infty}\oint_{\Gamma}\frac{\cos z}{z^2+a^2}\, dz=\operatorname{Re}\,\left(\displaystyle\int_{-\infty}^{\infty} \frac{e^{iz}}{z^{2} + a^{2}}\, dz\right) =\operatorname{Re}\,(2\pi ib)=\operatorname{Re}\,(2\pi i\frac{e^{-a}}{2ia}) = \frac{\pi e^{-a}}{a} $
Similarly, with $\displaystyle\int_{-\infty}^{\infty} \frac{x \sin x}{x^{2} + a^{2}}\ dx$ we change $\sin x$ to $\operatorname{Im}\,(e^{ix})$ and make the function complex-valued.
$g(z)=\frac{z\sin z}{z^2+a^2}=\operatorname{Im}\,\left(\frac{ze^{iz}}{(z+ia)(z-ia)}\right)$
Jordan's lemma again can be used to show that the integral around the arc tends to zero as $R\to\infty$. We then proceed to find the residues. The residue of pole $z_1=ia$ is
$b=\frac{iae^{-a}}{2ia}=\frac{e^{-a}}{2}$
$z_1$ is the unique pole in the contour, so upon multiplying its residue, $b$, with $2\pi i$ we find: $ \displaystyle\int_{-\infty}^{\infty} \frac{x \sin x}{x^{2} + a^{2}}\, dx= \lim_{R\to\infty}\oint_{\Gamma} \frac{x \sin x}{x^{2} + a^{2}}\, dz= \operatorname{Im}\,\left(\displaystyle\int_{-\infty}^{\infty} \frac{ze^{iz}}{(z+ia)(z-ia)}\, dz\right)= \operatorname{Im}\,(2\pi ib)= \operatorname{Im}\,(2\pi i \frac{e^{-a}}{2})= \operatorname{Im}\,(\pi e^{-a}i)= \pi e^{-a} $