Finding $f^{-1}$ in the YASHE keygen algorithm
To invert a polynomial in the quotient ring $F_q[X]/(\phi(X))$ there are two cases:

-> Either $\phi$ is irreducible modulo $q$, in which case every polynomial is inversible

-> Either $\phi$ is not irreducible, and one reasons with the Chinese remainder theorem.

In the first case, to find the inverse, just use Extended Euclides to find two polynomials $U,V$ such that

$$Uf+V\phi=1$$

(I'll let you deduce why $gcd(\phi,f)=1$) and therefore $Uf=1 \in R$. 

For the YASHE parameters, $\phi$ is not irreducible, and therefore a quick answer to your question is

$\mbox{ if } gcd(f,\phi)\neq 1$ then $\phi$ is not invertible,
if $gcd(f,\phi)= 1$ use Euclides as before.