Consider the mapping $f:x\to\frac{1}{x}, (x\ne0)$. It is trivial to see that $f(f(x))=x$.
My question is whether or not there exists a continuous map $g$ such that $g(g(g(x)))\equiv g^{3}(x)=x$? Furthermore, is there a way to find out if there is such a function that $g^{p}(x)=x$ for a prime $p$?
Edit: I realise I was a little unclear - I meant to specify that it was apart from the identity map. The other 'condition' I wanted to impose isn't very precise; I was hoping for a function that didn't seem defined for the purpose. However, the ones that are work perfectly well and they certainly answer the question.
Consider the class of Möbius transformations: $$f(x) = {ax+b\over cx+d}$$ for some constants $a,b,c,d$. If we represent Möbius transformation $f$ by its matrix of coefficients: $$\hat f = \pmatrix{ a&b \\ c&d }$$ then it turns out that to compose two Möbius transformations $f$ and $g$ we just multiply their corresponding matrices.
In particular, if $f$ is a Möbius transformation with matrix $\hat f$, then $f(f(f(x)))$ is also a Möbius transformation, with matrix ${\hat f}{}^3$.
So it suffices to find a $2\times 2$ matrix $M$ with $M^3 = I$. There are numerous examples, but one such is $$\def\ang{{\frac{2\pi}3}}\pmatrix{\cos\ang & \sin\ang \\ -\sin\ang & \cos\ang} = \pmatrix{-\frac12 & \frac{\sqrt3}2 \\ -\frac{\sqrt3}2 & -\frac12 }.$$ This is just the matrix for the linear transformation of the plane that rotates the plane by a one-third turn about the origin.
So the corresponding Möbius transformation with period 3 is $$f(x) = {x-\sqrt 3\over x\sqrt3 + 1}.$$
By replacing $2\pi\over 3$ with $2\pi\over n$, you can construct a function with any period you want.
Note that you are not restricted to $M$ with $M^3 = I$. Since $I$ and $kI$ are the same when considered as Möbius transformation, $M^3 = kI$ will work for any $k$.