This is a little too long for a comment.
When considering in $\Bbb R^2$ the product of the Lebesgue $\sigma$-algebra for $\Bbb R$, the question is already answered by @Kavi Rama Murthy here: If the area under graph of $f$ is measurable then $f$ is measurable .
So the step that remains is due to the fact that the Lebesgue $\sigma$-algebra for $\Bbb R^2$ is NOT the product of the Lebesgue $\sigma$-algebra for $\Bbb R$. It is the completion of the product $\sigma$-algebra.
Let $f: \Bbb R \rightarrow [0,\infty]$ be a function. Let $E=\{(x,y)\in \Bbb R^2:0 < y < f(x)\} $ and suppose that $E$ is Lebesgue measurable in $\Bbb R^2$.
For any $a \in [0, \infty]$, let us define the section $E^{a} = \{x:(x,a)\in E\}$. It is easy to see that $E^{a} = \{x:(x,a)\in E\}= \{x: f(x) >a\}$.
By Fubini Theorem for completion of product $\sigma$-algebras, we have that for almost all $a\in [0, \infty]$, $E^a$ is measurable. That means, there exist a set $N \subset [0, \infty]$, such that $\lambda(N) =0$ and for all $a \in [0, \infty] \setminus N$,
$E^a$ is measurable.
So it remains to prove that for all $a\in N$, we also have that $E^a$ is measurable.
Note that $E^{\infty} = \emptyset$ and it is measurable. So, we can assume, without loss of generality that $N \subset [0, \infty)$,
Given $a \in N$. Then $0 \leq a < \infty$. Since $\lambda(N) =0$, given any $\varepsilon >0$, we have that $(a, a +\varepsilon) \nsubseteq N$. So, we can build a strictly decreasing sequence $(a_n)_n$ such that for all $n$, $a_n \in (a, \infty) \setminus N$ and $a_n \to a$.
So, for all $n$, $E^{a_n}$ is measurable and
$$E^{a} = \{x: f(x) >a\}= \bigcup_n \{x: f(x) >a_n\} =\bigcup_n E^{a_n}$$
So $E^a$ is measurable.
So we have proved that for all $a \in [0, \infty]$ , $E^a$ is measurable. Since $E^{a} =\{x: f(x) >a\}$, we have that for all $a \in [0, \infty]$, $\{x: f(x) >a\}$ is measurable, which means that $f$ is Lebesgue measurable.
Best Answer
$g=k\circ h$ where $h(x,y)=(f(x),y)$ and $k(a,b)=a-b$. [ Here $h:X\times \mathbb R \to \mathbb R^{2}$ and $k:\mathbb R^{2} \to \mathbb R$]. $k:\mathbb R^{2} \to \mathbb R$ is Borel measurable because it is continuous. To show that $h$ is measurable it is enough to show that $h^{-1} (A \times B) \in \mathcal A \times B(\mathbb R)$ for $A,B \in \mathcal B(\mathbb R)$. This is clear because $h^{-1} (A \times B)=f^{-1}(A) \times B$.
I have assumed that $f$ takes only finite values. To handle the general case let $g(x)=f(x)$ if $f(x) <\infty$ and $0$ if $f(x)=\infty$. Let $F=\{(x,y):0\leq y <g(x)\}$. Then $E=(f^{-1}\{\infty\}\times [0,\infty)) \cup [(f^{-1}\{\mathbb R\}\times \mathbb R) \cap F]$.