What is a condition for two real functions $f,g$ to "commute", so $f(g(x))=g(f(x))$?

There is, in general, no characterization other than the evaluation of $f(g(x))$ and $g(f(x))$.

Also, for fixed $f$ there is no an easy way to find all the $g$ such that $f \circ g = g \circ f$.

Special cases can be studied. For example, a theorem of J. Lipiński says that if $f$ is a continuous and strictly monotonic function on an interval $I$ such that $f(I) \subseteq I$ then there is an infinity of solutions $g$ (depending on an arbitrary function).