How do I find the difference equation from a transfer function?
A transfer function $H(Z)$ can be written as $H(Z)=\frac{Y(Z)}{X(Z)}$. Then, your $H(Z)$ can be written as

$\frac{Y(Z)}{X(Z)}=1-\cos\theta~Z^{-1}+Z^{-2}$ or 

$Y(Z)=X(Z)(1-\cos\theta~ Z^{-1}+Z^{-2})$

Now taking the inverse $Z$transform, we get the difference equation as

$y(n)=x(n)-\cos\theta~x(n-1)+x(n-2)$.

I hope this help you.