Let $H$ be a self-adjoint operator on a Hilbert space $\mathcal{H}$, not necessarily bounded. Consider two measurable functions $f$ and $g$ and define the operators $f(H)$ and $g(H)$ symbolically. In what sense are these operators defined? And is it true that $[f(H), g(H)] = 0$?
I have some idea of "functional calculus" and the spectral theorem but its vague and I'd like some help for clarification.
By the spectral Theorem you are allowed to think that $\mathcal H=L^2(X,\mu)$, where $(X,\mu)$ is a $\sigma$-finite measure space, and that your operator (which I am going to call) $T$ is given by $$ T(\xi)|_x = \phi(x)\xi(x), \quad \forall \xi\in \mathcal H, \quad \forall x\in X, \tag 1 $$ where $\phi$ is some measurable real valued function on $X$, the domain of $T$ being $$ D(T)= \{\xi\in L^2(X,\mu): \phi\xi\in L^2(X,\mu)\}. $$
Incidentally it is interesting to notice that, no matter how wildly unbounded $\phi$ is, the domain $D(T)$ will always be dense!
This said, given any Borel measurable function $f$ on $\mathbb R$, one has that $f(T)$ is defined exactly as in (1), except that $\phi$ is replaced by $f\circ\phi$. Doing the same for $g$ you may now easily check that the domains of $f(T)g(T)$ and $g(T)f(T)$ coincide and that $f(T)$ commutes with $g(T)$ on that common domain, simply because pointwise multiplication is commutative!
All of this bonanza takes place because we are basing everything on a single self-adjoint operator. Should we be interested in working with two different operators (think position and momentum in quantum mechanics) hell would quickly break loose!