I am able to solve the equation correctly, but I need to use inverse function to find the degree. The actual answer is the following:
$$x=\frac{\pi}{8},\frac{5\pi}{8},\frac{9\pi}{8},\frac{13\pi}{8}$$ So I got $\tan x=-1+\sqrt2$, and $\tan x=-1-\sqrt2$. How can I straight away know which trigonometric identity to use like half angle in the problem?
It's a bit tricky, but you can deduce this with a little experimenting and the appropriate trig formula. First we use $$1+\tan^2 x = \sec^2 x$$
Since $\tan x = 1\pm \sqrt 2, \tan^2 x = 3\pm2\sqrt 2$ and so $\sec^2 x = 4\pm 2\sqrt 2$ and therefore $$\cos^2 x = \frac 1{4\pm 2\sqrt 2} = \frac {2\mp \sqrt 2}4$$ and $$\sin^2 x = 1 - \cos^2 x = \frac {2\pm \sqrt 2}4$$
Now $$\begin{align}\cos 2x &= \cos^2 x - \sin^2 x\\&= \frac {2 \mp \sqrt 2}4 - \frac {2\pm \sqrt 2}4\\&=\mp\frac{\sqrt 2}2\end{align}$$
I'm sure you can take it from there.
Probably if you'd shown us the original problem (something that generally is really wise to do when asking for help), we could have pointed out ways to have solved for a cosine or sine value directly, so that this extra calculation could be avoided. It is commonly helpful in solving trig problems to work towards expressing it in terms of sine and cosine as early as possible (though of course, there are exceptions).