You can see that this map is both injective and surjective, and thus bijective, and therefore has an inverse.
To find the inverse, you just look at the function "backwards". Since $f(3) = 1$, we may say that $f^{-1}(1) = 3$, and similarly $f^{-1}(2) = 1$ and $f^{-1}(3) = 2$. For any other $s \in S$, we see that $f(s) = s$, and applying $f^{-1}$, we see that $f^{-1}(s) = s$.
To show that $f \circ f \circ f$ (call it $f^3$), we must show that for all $s \in S$, $f^3(s) = s$.
To do this, look at where the first power of $f$ sends any element $s$. For $s \in S - \{1,2,3\}$, what happens? Can you generalize this to any other powers?
For $s \in \{1,2,3\}$, simply apply $f$ three times ("by hand"), and see what you get!