Hint
Let $A$ be an square matrix with coefficients in a field $K$, and let $g$ be its minimal polynomial.
Then the epimorphism $K[X]\to K[A]$, $f\mapsto f(A)$ induces an isomorphism $K[X]/(g)\to K[A]$.
Assume that $g$ splits over $K$.
Then the Chinese Remainder Theorem says that this algebra is isomorphic to the product of the $K[X]/(X-\lambda)^{m(\lambda)}$, where $\lambda$ is an root of $g$ and $m(\lambda)$ its multiplitity.
Moreover the natural morphism from $K[X]$ to $K[X]/(X-\lambda)^{m(\lambda)}$ attaches to $f\in K[X]$ its degree $ < m(\lambda)$ Taylor polynomial at $\lambda$.
EDIT 1. The interest of the above observation (which is of course entirely classical) is that it gives you a formula for $f(A)$. [If $K=\mathbb C$ the formula holds also for the functions which are holomorphic on the spectrum --- like the exponential.]
[Technical point: In positive characteristic, $\frac{f^{(n)}}{n!}$ is not defined as $f^{(n)}$ divided by $n!$ (Here $f$ is in $K[X]$.)]
EDIT 2. This is to explain how Andrea's very nice answer can be obtained in this setting. Once you've noticed the isomorphism $K[A]=K[X]/(g)$, it's clear that $f(A)$ is invertible iff $f$ is invertible mod $g$, iff $f$ is prime to $g$.