Sufficient condition for measurability for functions with values in $[-\infty,\infty]$ I have proved the following result:
"Suppose $(X,\mathcal{S})$ is a measurable space and $f:X\to [-\infty,\infty]$ is a function such that $f^{-1}((a,\infty])\in\mathcal{S}$ for all $a\in\mathbb{R}$.
Then $f$ is an $\mathcal{S}$-measurable function."
and I would like to know if my proof is correct, thanks.

My proof (edited to take into account Alphie's answer):
Let $\tau:=\{A\subset[-\infty,\infty]:f^{-1}(A)\in\mathcal{S}\}$: if we can prove that the set of all Borel subsets of $[-\infty,\infty]$ is a subset of $\tau$ then the claim will follow because it will imply that $f^{-1}(B)\in\mathcal{S}$ for every Borel subset of $[-\infty,\infty]$, which is the definition of an $\mathcal{S}$-measurable function $f:X\to [-\infty,\infty]$.
We first prove that $\tau$ is a $\sigma$-algebra on $[-\infty,\infty]$:

*

*$\emptyset\subset [-\infty,\infty],\ f^{-1}(\emptyset)=\emptyset$ and being $\mathcal{S}$ a $\sigma$-algebra $\emptyset\in\mathcal{S}$ so $\emptyset\in\tau$;


*$E\in\tau\Rightarrow E\subset [-\infty,\infty],\ f^{-1}(E)\in\mathcal{S}\Rightarrow X\setminus f^{-1}(E)\overset{(2.33a)}{=}f^{-1}([-\infty,\infty]\setminus E)\in\mathcal{S}$ and since $[-\infty,\infty]\setminus E\subset [-\infty,\infty]$ we have $[-\infty,\infty]\setminus E\in\mathcal{S}$ so $\tau$ is closed under complementation;


*$E_1, E_2,\dots\in\tau\Rightarrow f^{-1}(E_1),f^{-1}(E_2),\dots\in\mathcal{S}$ so $f^{-1}(\bigcup_{k=1}^{\infty}E_k)\overset{(2.33b)}{=}\bigcup_{k=1}^{\infty}f^{-1}(E_k)\in\mathcal{S}\Rightarrow \bigcup_{k=1}^{\infty}E_k\in\mathcal{S}$ so $\tau$ is closed under countable unions.
So, $\tau$ is a $\sigma$-algebra on $[-\infty,\infty]$, as desired.
By hypothesis, $\tau$ contains $\{(a,\infty]:a\in\mathbb{R}\}$ and being a $\sigma$-algebra we have that it also contains $\{[-\infty,b]:b\in\mathbb{R}\}$, $\{(a,b]:a,b\in\mathbb{R}\}$ and thus all the intervals of the form $(a,b)=\bigcup_{k=1}^{\infty}(a,b-\frac{1}{k}]$, $(-\infty, b)=\bigcup_{k=1}^{\infty} (-k,b-\frac{1}{k}]$, $[-\infty,b)=\bigcup_{k=1}^{\infty}[-\infty,b-\frac{1}{k}]$ and $[a,\infty]=[-\infty,\infty]\setminus [-\infty,a)$, $[-\infty, \infty) =\bigcup_{k=1}^{\infty}[-\infty,k)$,  $ (a, \infty] =\bigcup_{k=1}^{\infty} [a+\frac{1}{k},\infty]$, $ (-\infty, \infty] =\bigcup_{k=1}^{\infty} (-k,\infty]$,  and the sets $\{\infty\} =[-\infty, \infty] \setminus [-\infty, \infty)$, $\{-\infty\} =[-\infty, \infty] \setminus (-\infty, \infty]$, $\{-\infty,+\infty\}=\{-\infty\}\cup\{+\infty\}$.
So, since every open subset of $\mathbb{R}$ can be written as a countable union of disjoint open intervals we have that $\tau$ is a $\sigma$-algebra on $[-\infty,\infty]$ that contains all the  open subsets of $\mathbb{R}$.

Let $\tau_{|\mathbb{R}}:=\{B\cap\mathbb{R}:B\in\tau\}$: we claim that $\tau_{|\mathbb{R}}$ is a $\sigma$-algebra on $\mathbb{R}$.

*

*$\emptyset\in\tau$ and $\emptyset\cap\mathbb{R}=\emptyset$ so $\emptyset\in\tau_{|\mathbb{R}}$;


*$E\in\tau_{|\mathbb{R}}\Rightarrow E=B\cap\mathbb{R}$ for some $B\in\tau$ so $\mathbb{R}\setminus E=\mathbb{R}\setminus (B\cap\mathbb{R})=(\mathbb{R}\setminus B) \cup (\mathbb{R}\setminus\mathbb{R})=\mathbb{R}\setminus B=(\mathbb{R}\setminus B)\cap \mathbb{R}$ and $\mathbb{R}, B\in\tau\overset{(2.25b)}{\Rightarrow}\mathbb{R}\setminus B\in\tau$ so $\mathbb{R}\setminus E\in\tau_{|\mathbb{R}}$;


*$E_1, E_2,\dots\in\tau_{|\mathbb{R}}\Rightarrow E_k=B_k\cap\mathbb{R},\ B_k\in\tau,\ k\geq 1$. $\bigcup_{k=1}^{\infty}E_k=\bigcup_{k=1}^{\infty}(B_k\cap\mathbb{R})=(\bigcup_{k=1}B_k)\cap\mathbb{R}$ and $\bigcup_{k=1}B_k\in\tau$ so $\bigcup_{k=1}^{\infty}E_k\in\tau_{|\mathbb{R}}$.
So, $\tau_{|\mathbb{R}}$ is a $\sigma$-algebra on $\mathbb{R}$, as desired.
Now, if $O$ is an open subset of $\mathbb{R}$ then as we said before $O\in\tau$ and since $O=O\cap\mathbb{R}$ we have that $O\in\tau_{|\mathbb{R}}$ so $\tau_{|\mathbb{R}}$ is a $\sigma$-algebra on $\mathbb{R}$ containing all the open subsets of $\mathbb{R}$: since the set $\mathcal{B}$ of Borel subsets of $\mathbb{R}$ is by definition the smallest such $\sigma$-algebra we have that $\mathcal{B}\subset\tau_{|\mathbb{R}}$ and since $\tau_{|\mathbb{R}}\subset\tau$ ($A\in\tau_{|\mathbb{R}}\Rightarrow A=B\cap\mathbb{R},\ B\in\tau$ and since $\mathbb{R}\in\tau$ too we have that $A=B\cap\mathbb{R}\in\tau$) we have that $\mathcal{B}\subset\tau$.
Now, let $C$ be a Borel subset of $[-\infty,\infty]$: then by definition there exists a Borel subset $B\subset\mathbb{R}$ such that $C=B$ or $C=B\cup\{-\infty\}$ or $C=B\cup\{\infty\}$ or $C=B\cup\{-\infty,\infty\}$: $B\in\tau$ and also $\{-\infty\},\{\infty\},\{-\infty,\infty\}\in\tau$ so their possible unions are also all in $\tau$ thus $C\in\tau$ too so $\tau$ also contains all the Borel subsets of $[-\infty,\infty]$ so $f^{-1}(B)\in\mathcal{S}$ for all $B\in [-\infty,\infty]$ and in particular for all $B\in\mathcal{B}$ so  $f$ is an $\mathcal{S}$-measurable function, as desired. $\square$

useful definitions
DEF. (Measurable function). Suppose $(X,\mathcal{S})$ is a measurable space. A function $f:X\to [-\infty,\infty]$ is called $\mathcal{S}$-measurable if $f^{-1}(B)\in\mathcal{S}$ for every Borel set $B\subset[-\infty,\infty]$
DEF. (Borel subset of $[-\infty,\infty]$. A subset of $[-\infty,\infty]$ is called a Borel set if its intersection with $\mathbb{R}$ is a Borel set. In other words a set $C\subset [-\infty,\infty]$ is a Borel set iff there exists a Borel set $B\subset\mathbb{R}$ such that $C=B$ or $C=B\cup\{\infty\}$ or $C=B\cup \{-\infty\}$ or $C=B\cup\{\infty,\infty\}$
 A: "Now, let $B$ be a Borel subset of $\mathbb R$: then $B$ is either an open subset of $\mathbb R$ or it can be obtained from open subsets of $\mathbb R$ by using the operations allowed in a σ-algebra (like complementation, difference, countable union and intersection)"
This statement is a bit loose, but can be formalized using transfinite induction. The main problem is that apparently there exist Borel sets that cannot be arrived at by a countable sequence of operations allowed in a $\sigma$-algebra. See here.
We can argue alternatively as follows:
Define $\tau|_\mathbb R:=\{B\cap \mathbb R:B\in \tau\}$. Using the fact that $\tau$ is a $\sigma$-algebra on $[-\infty,+\infty]$, one checks that $\tau|_\mathbb R$ is a $\sigma$-algebra on $\mathbb R$. Moreover, $\tau|_\mathbb R\subset \tau$, since $\mathbb R$ is a Borel subset of  $[-\infty,+\infty]$.
Now, you have argued that $\tau$ contains all open subsets of $\mathbb R$, but in fact these sets are all contained in $\tau|_\mathbb R$. Since the Borel $\sigma$-algebra on $\mathbb R$ is the smallest $\sigma$-algebra on $\mathbb R$ containing all open subsets of $\mathbb R$, and $\tau|_\mathbb R$ is such a $\sigma$-algebra, we deduce that $\tau|_\mathbb R$ contains all open subsets of $\mathbb R$. Finally,  since $\tau|_\mathbb R\subset \tau$, it must be that $\tau$ contains all open subsets of $\mathbb R$ as well.
