[proofplan]
We express the two infinite level sets as countable intersections of measurable threshold preimages. The measurability of each threshold set follows from the measurability of $f$ and the fact that the corresponding threshold intervals are Borel subsets of $[-\infty,\infty]$. Once the two infinite level sets are measurable, the finite-valued set is the complement of their union, so it is measurable by the closure properties of the $\sigma$-algebra $\mathcal{M}$.
[/proofplan]
[step:Express the positive infinite level set as a countable threshold intersection]
For each $n\in\mathbb{N}$, define
\begin{align*}
A_n:=\{x\in X:f(x)>n\}.
\end{align*}
The interval $(n,\infty]$ is a Borel subset of $[-\infty,\infty]$, and
\begin{align*}
A_n=f^{-1}((n,\infty]).
\end{align*}
Since $f$ is $\mathcal{M}/\mathcal{B}([-\infty,\infty])$-measurable, $A_n\in\mathcal{M}$ for every $n\in\mathbb{N}$.
We claim that
\begin{align*}
\{x\in X:f(x)=\infty\}=\bigcap_{n=1}^{\infty}A_n.
\end{align*}
If $f(x)=\infty$, then $f(x)>n$ for every $n\in\mathbb{N}$, so $x\in\bigcap_{n=1}^{\infty}A_n$. Conversely, if $x\in\bigcap_{n=1}^{\infty}A_n$, then $f(x)>n$ for every $n\in\mathbb{N}$. No finite real number has this property, and $f(x)$ cannot be $-\infty$, so $f(x)=\infty$. Therefore the displayed equality holds. Since $\mathcal{M}$ is closed under countable intersections,
\begin{align*}
\{x\in X:f(x)=\infty\}\in\mathcal{M}.
\end{align*}
[guided]
For each positive integer $n$, define the threshold set
\begin{align*}
A_n:=\{x\in X:f(x)>n\}.
\end{align*}
The reason for using these sets is that the value $\infty$ is characterized among extended [real numbers](/page/Real%20Numbers) by being larger than every integer. First we verify measurability of each $A_n$. The interval $(n,\infty]$ is a Borel subset of $[-\infty,\infty]$, and by definition of preimage,
\begin{align*}
A_n=f^{-1}((n,\infty]).
\end{align*}
Because $f$ is measurable as a map from $(X,\mathcal{M})$ to $([-\infty,\infty],\mathcal{B}([-\infty,\infty]))$, this preimage belongs to $\mathcal{M}$. Hence $A_n\in\mathcal{M}$ for every $n\in\mathbb{N}$.
Now we identify the level set. We prove both containments:
\begin{align*}
\{x\in X:f(x)=\infty\}=\bigcap_{n=1}^{\infty}A_n.
\end{align*}
If $x\in X$ satisfies $f(x)=\infty$, then $\infty>n$ for every $n\in\mathbb{N}$, so $x\in A_n$ for every $n$. Thus $x\in\bigcap_{n=1}^{\infty}A_n$.
Conversely, suppose $x\in\bigcap_{n=1}^{\infty}A_n$. Then $f(x)>n$ for every $n\in\mathbb{N}$. A finite real number cannot exceed every positive integer, and $-\infty$ exceeds no real integer. Therefore the only possible extended real value is $f(x)=\infty$. This proves the equality. Since each $A_n$ lies in $\mathcal{M}$ and $\mathcal{M}$ is a $\sigma$-algebra, it is closed under countable intersections. Hence
\begin{align*}
\{x\in X:f(x)=\infty\}\in\mathcal{M}.
\end{align*}
[/guided]
[/step]
[step:Express the negative infinite level set as a countable threshold intersection]
For each $n\in\mathbb{N}$, define
\begin{align*}
B_n:=\{x\in X:f(x)<-n\}.
\end{align*}
The interval $[-\infty,-n)$ is a Borel subset of $[-\infty,\infty]$, and
\begin{align*}
B_n=f^{-1}([-\infty,-n)).
\end{align*}
Thus $B_n\in\mathcal{M}$ for every $n\in\mathbb{N}$.
As above,
\begin{align*}
\{x\in X:f(x)=-\infty\}=\bigcap_{n=1}^{\infty}B_n.
\end{align*}
Indeed, $-\infty<-n$ for every $n\in\mathbb{N}$, while no finite real number is smaller than every negative integer. Since $\mathcal{M}$ is closed under countable intersections,
\begin{align*}
\{x\in X:f(x)=-\infty\}\in\mathcal{M}.
\end{align*}
[/step]
[step:Obtain the finite-valued set by taking the complement of the two infinite level sets]
Define
\begin{align*}
E_+:=\{x\in X:f(x)=\infty\}
\end{align*}
and
\begin{align*}
E_-:=\{x\in X:f(x)=-\infty\}.
\end{align*}
The preceding steps show that $E_+\in\mathcal{M}$ and $E_-\in\mathcal{M}$. Since $\mathcal{M}$ is closed under finite unions, $E_+\cup E_-\in\mathcal{M}$.
For every $x\in X$, the extended real value $f(x)$ is finite exactly when it is neither $\infty$ nor $-\infty$. Therefore
\begin{align*}
\{x\in X:|f(x)|<\infty\}=X\setminus(E_+\cup E_-).
\end{align*}
Since $\mathcal{M}$ is closed under complements, the right-hand side belongs to $\mathcal{M}$. Hence
\begin{align*}
\{x\in X:|f(x)|<\infty\}\in\mathcal{M}.
\end{align*}
This proves all three asserted measurability conclusions.
[/step]