I've started solving problems from my functional analysis course and I don't know exactly how to do this one:
Given $f:X\to\overline{\mathbb{R}}$ a function and $Y=f^{-1}(\mathbb{R})$. Prove that $f$ is measurable if and only if $f^{-1}(\{\infty\})$ and $f^{-1}(\{-\infty\})$ are both measurable sets, and the restriction $f\mid_{Y}$ is measurable.
The topology I'm considering in $\overline{\mathbb{R}}$ is the one that has as basis the sets of the form $(a,b)$, $(a,\infty]$ and $[-\infty,b)$, where $a,b$ are both real values with $a<b$. I've tried proving the double implication:
$\Longrightarrow$ : I assume $f$ is measurable. From this is trivial that $f\mid_Y$ is measurable. The problem is the condition over the preimages of both infinities. I don't get why they have to be isolated since $\{\infty\}$, $\{-\infty\}$ are not elements of the topology, and $f$ being measurable just takes care of the preimages of the elements of the topology. How can I do this?
$\Longleftarrow$ : This one was easy since the union of measurable sets is measurable so given that the preimages of both infinities and $\mathbb{R}$ were measurable it was done (I think, correct me if I'm wrong please).
How can I do the part of the infinities in the first implication? Any help or hint will be appreciated, thanks in advance.