You need to find a solution $\bmod$ every prime power factor of $g$ and then stitch them together using the chinese remainder theorem/algorithm.
However, if there is a prime $p$ that is congruent to $3\bmod 4$ then it is impossible, this is because if $g$ is a primite root $\bmod p$ then $-1=g^{(p-1)/2}$, and this number cannot be a square if $(p-1)/2$ is odd.
It is also impossible for $4$ to divide $g$.
So $g$ is of the form $p_1^{a_1}p_2^{a_2}\dots p_n^{a_n}$ or $2p_1^{a_1}p_2^{a_2}\dots p_n^{a_n}$ where every prime is congruent to $1\bmod 4$.
Now, there is no known easy way to find a solution to $x^2\equiv -1 \bmod p^a$ ( it is easy to show that there are exactly two solutions, because a primitive root exists). The best way is probably to look for a primitive root. testing whether a number $r$ is a primitive root can be done in time $\log(p^a)^2$ by checking if $r^{p-1/q}$ is $1\bmod p^k$ for each prime $q$ dividing $\varphi(p^k)$. The probability you pick a generator each time is $\frac{p-1}{p}$, so this method is pretty fast. After you have a generator your answer is $g^{(p-1)/4}$ and $g^{3(p-1)/4}$.