Obviously the polynomial $a(x)$ has to be coprime to $m(x)$ for otherwise the common factor will always prevent this. If the factorization of $m(x)$ to powers of irreducible polynomials is
$$
m(x)=\prod_i p_i(x)^{a_i},
$$
then by the Chinese remainder theorem
$$
\mathbb{F_p}[x]/(m(x))\simeq\bigoplus_i\mathbb{F_p}[x]/(p_i(x)^{a_i}).
$$
Denote $R_i=\mathbb{F_p}[x]/(p_i(x)^{a_i}).$ The coset of $a(x)$ is a unit of $R_i$ as $p_i(x)\nmid a(x)$. Can you count the size of the unit group of $R_i$?
If you know that $|R_i^*|=n_i$, then Lagrange's theorem tells you that
$$
a(x)^{n_i}\equiv 1\pmod{p_i(x)^{a_i}}.
$$
For the rest you are expected to mimic the integer case and apply Chinese remainder theorem backwards.
In some cases it is possible to replace the number $n_i$ by its proper divisor.
This is because the group $R_i^*$ is not always cyclic, and thus its exponent is strictly smaller than its cardinality. Consider the following. As explained in Alex Youcis' answer, when $a_i=1$, $R_i$ is a finite field, and thus $R_i^*$ is cyclic of order $q-1, q=|\mathbb{F_p}[x]/(p_i(x)|=p^{\deg p_i(x)}$. So we always have the congruence
$$
a(x)^{q-1}\equiv1 \pmod {p_i(x)},
$$
and thus $a(x)^{q-1}\equiv 1+p_i(x) b(x)\pmod {p_i(x)^2}$ for some polynomial $b(x)$. Raising this congruence to $p^{th}$ power gives then that
$$
a(x)^{p(q-1)}\equiv1\pmod {p_i(x)^2}
$$
even though $|\mathbb{F_p}[x]/(p_i(x)^2)^*|=q(q-1)>p(q-1)$ whenever $\deg p_i>1$.
This shows that for $R_i^*$ to be cyclic when $a_i>1$, it is necessary that $\deg p_i=1$. It would not be too difficult to analyze the structure of $R_i^*$ further, but at this point the reader can hopefully already appreciate that the exponent of $R_i$ depends on the parameters $\deg p_i$, $p$, and $a_i$ in a non-trivial way.