[proofplan]
We first verify the algebraic part directly from the defining commutation relation: the identity operator commutes with every operator in $M$, and the commutation relation is preserved under linear combinations and products. We then prove weak operator closure by taking a weakly convergent net in $M'$ and passing the identities $T_iS=ST_i$ to matrix coefficients. Strong operator closure is proved similarly, using pointwise norm convergence and boundedness of each fixed $S\in M$. Finally, when $M$ is self-adjoint, taking adjoints of the relation $TR=RT$ for $R\in M$ shows that $T^*$ also commutes with every element of $M$.
[/proofplan]
[step:Verify that the commutant is a unital algebra]
Let $I_H\in\mathcal{L}(H)$ denote the identity operator on $H$. For every $S\in M$,
\begin{align*}
I_HS=S=SI_H,
\end{align*}
so $I_H\in M'$.
Let $A,B\in M'$ and let $\lambda,\mu\in\mathbb C$. For every $S\in M$, using $AS=SA$ and $BS=SB$, we obtain
\begin{align*}
(\lambda A+\mu B)S=\lambda AS+\mu BS.
\end{align*}
Hence
\begin{align*}
(\lambda A+\mu B)S=\lambda SA+\mu SB=S(\lambda A+\mu B).
\end{align*}
Thus $\lambda A+\mu B\in M'$.
For products, again fix $S\in M$. Since $B\in M'$, we have $BS=SB$, and since $A\in M'$, we have $AS=SA$. Therefore
\begin{align*}
(AB)S=A(BS)=A(SB)=(AS)B=(SA)B=S(AB).
\end{align*}
Thus $AB\in M'$. Therefore $M'$ is a unital subalgebra of $\mathcal{L}(H)$.
[/step]
[step:Pass commutation relations to weak operator limits]
Let $(T_i)_{i\in I}$ be a net in $M'$ which converges to an operator $T\in\mathcal{L}(H)$ in the weak operator topology. We prove that $T\in M'$.
Fix $S\in M$ and $\xi,\eta\in H$. Since $T_i\in M'$, we have $T_iS=ST_i$ for every $i\in I$, and therefore
\begin{align*}
(T_iS\xi,\eta)_H=(ST_i\xi,\eta)_H.
\end{align*}
The left-hand side converges to $(TS\xi,\eta)_H$ because $S\xi\in H$ is fixed and $T_i\to T$ weakly. For the right-hand side, using the adjoint $S^*\in\mathcal{L}(H)$ and the convention that the Hilbert-space [inner product](/page/Inner%20Product) is linear in the first argument, we have
\begin{align*}
(ST_i\xi,\eta)_H=(T_i\xi,S^*\eta)_H.
\end{align*}
Since $\xi$ and $S^*\eta$ are fixed vectors in $H$, weak operator convergence gives
\begin{align*}
(T_i\xi,S^*\eta)_H\to (T\xi,S^*\eta)_H.
\end{align*}
Again by the defining property of the adjoint,
\begin{align*}
(T\xi,S^*\eta)_H=(ST\xi,\eta)_H.
\end{align*}
Passing to the limit in the equality of matrix coefficients gives
\begin{align*}
(TS\xi,\eta)_H=(ST\xi,\eta)_H.
\end{align*}
Since $\xi,\eta\in H$ were arbitrary, the operator $(TS-ST)\in\mathcal{L}(H)$ satisfies
\begin{align*}
((TS-ST)\xi,\eta)_H=0
\end{align*}
for every $\xi,\eta\in H$. Taking $\eta=(TS-ST)\xi$ gives
\begin{align*}
\|(TS-ST)\xi\|_H^2=0
\end{align*}
for every $\xi\in H$, so $TS=ST$. Since $S\in M$ was arbitrary, $T\in M'$. Thus $M'$ is weak-operator closed.
[guided]
We want to show that a weak operator limit of operators commuting with every element of $M$ still commutes with every element of $M$. Let $(T_i)_{i\in I}$ be a net in $M'$ and suppose $T_i\to T$ in the weak operator topology, where $T\in\mathcal{L}(H)$. By definition of weak operator convergence, for every pair of vectors $\alpha,\beta\in H$,
\begin{align*}
(T_i\alpha,\beta)_H\to (T\alpha,\beta)_H.
\end{align*}
Fix one operator $S\in M$. To prove $TS=ST$, it is enough to prove equality of all matrix coefficients. Thus fix $\xi,\eta\in H$. Because each $T_i$ belongs to $M'$, it commutes with $S$, so
\begin{align*}
(T_iS\xi,\eta)_H=(ST_i\xi,\eta)_H.
\end{align*}
Now we pass both sides to the limit. The left-hand side is directly in the form required by weak operator convergence, because $S\xi$ is a fixed vector of $H$. Hence
\begin{align*}
(T_iS\xi,\eta)_H\to (TS\xi,\eta)_H.
\end{align*}
The right-hand side is not immediately a weak matrix coefficient of $T_i$, because $T_i$ is followed by $S$. We move $S$ to the second slot using the adjoint. Since $S\in\mathcal{L}(H)$, its adjoint $S^*\in\mathcal{L}(H)$ exists, and with the inner product linear in the first argument,
\begin{align*}
(ST_i\xi,\eta)_H=(T_i\xi,S^*\eta)_H.
\end{align*}
Now $\xi$ and $S^*\eta$ are fixed vectors, so weak operator convergence gives
\begin{align*}
(T_i\xi,S^*\eta)_H\to (T\xi,S^*\eta)_H.
\end{align*}
Using the adjoint relation once more,
\begin{align*}
(T\xi,S^*\eta)_H=(ST\xi,\eta)_H.
\end{align*}
Therefore the common limit of the two sides is both $(TS\xi,\eta)_H$ and $(ST\xi,\eta)_H$, so
\begin{align*}
(TS\xi,\eta)_H=(ST\xi,\eta)_H.
\end{align*}
Because this holds for every $\eta\in H$, the vector $(TS-ST)\xi$ has zero inner product with every vector in $H$. In particular, taking $\eta=(TS-ST)\xi$ gives
\begin{align*}
\|(TS-ST)\xi\|_H^2=0.
\end{align*}
Thus $(TS-ST)\xi=0$. Since $\xi\in H$ was arbitrary, $TS=ST$. Since $S\in M$ was arbitrary, $T\in M'$. This proves that $M'$ is closed in the weak operator topology.
[/guided]
[/step]
[step:Pass commutation relations to strong operator limits]
Let $(T_i)_{i\in I}$ be a net in $M'$ which converges to an operator $T\in\mathcal{L}(H)$ in the strong operator topology. We prove that $T\in M'$.
Fix $S\in M$ and $\xi\in H$. Since $T_i\to T$ strongly, applying the convergence to the fixed vector $S\xi\in H$ gives
\begin{align*}
T_iS\xi\to TS\xi
\end{align*}
in the norm of $H$. Since $T_i\in M'$, we have $T_iS\xi=ST_i\xi$ for every $i\in I$. Also, strong convergence gives $T_i\xi\to T\xi$ in $H$, and the [bounded linear operator](/page/Bounded%20Linear%20Operator) $S:H\to H$ is norm-continuous, so
\begin{align*}
ST_i\xi\to ST\xi
\end{align*}
in the norm of $H$. A net in a Hausdorff normed space has at most one norm limit, so $TS\xi=ST\xi$. Since $\xi\in H$ was arbitrary, $TS=ST$. Since $S\in M$ was arbitrary, $T\in M'$. Thus $M'$ is strong-operator closed.
[/step]
[step:Take adjoints when the original set is self-adjoint]
Assume now that $M$ is self-adjoint. Let $T\in M'$. We prove that $T^*\in M'$.
Fix $S\in M$. Since $M$ is self-adjoint, $S^*\in M$. Because $T\in M'$, $T$ commutes with $S^*$, so
\begin{align*}
TS^*=S^*T.
\end{align*}
Taking adjoints of both sides gives
\begin{align*}
(ST^*)=(T^*S).
\end{align*}
Thus $T^*S=ST^*$. Since $S\in M$ was arbitrary, $T^*\in M'$. Therefore $M'$ is self-adjoint whenever $M$ is self-adjoint.
Combining the previous steps, $M'$ is a unital subalgebra of $\mathcal{L}(H)$ closed in both the strong and weak [operator topologies](/page/Operator%20Topologies), and it is self-adjoint under the additional hypothesis that $M$ is self-adjoint.
[/step]