$\newcommand{\ep}{\epsilon} \newcommand{\R}{\mathbb{R}} \newcommand{\E}{\operatorname{\mathsf E}} \newcommand{\PP}{\operatorname{\mathsf P}}$
For any random variable (r.v.) $X$, you can write $X=X_+-X_-$, where $X_+:=\max(0,X)$ and $X_-:=\max(0,-X)$. Then you can write $$X_+=\int_0^\infty I\{X>x\}dx,\quad X_-=\int_0^\infty I\{-X>x\}dx,$$ and hence \begin{equation} X=\int_0^\infty (I\{X>x\}-I\{-X>x\})dx,\tag{1} \end{equation} where $I\{\cdot\}$ is the indicator function.
Addition in response to the editing of the post: Suppose that $g\colon\R\to\R$ is a Borel-measurable function such that $\E g(X)$ exists. By (1), \begin{equation} g(X)=\int_0^\infty (I\{g(X)>u\}-I\{-g(X)>u\})du. \tag{2} \end{equation} So, introducing the distribution (law) $\mu_X=\PP X^{-1}$ of $X$, by the Fubini theorem we have \begin{align*} \E g(X)&=\int_0^\infty (\E I\{g(X)>u\}-\E I\{-g(X)>u\})du \\ &=\int_0^\infty (\PP\{g(X)>u\}-\PP\{-g(X)>u\})du \\ &=\int_0^\infty [\mu_X(\{x\in\R\colon g(x)>u\})-\mu_X(\{x\in\R\colon -g(x)>u\})]du \\ &=\int_0^\infty du \Big(\int_\R\mu_X(dx)(I\{g(x)>u\}-I\{-g(x)>u\})\Big) \\ &=\int_\R\mu_X(dx)\int_0^\infty du\, (I\{g(x)>u\}-I\{-g(x)>u\}) \\ &=\int_\R\mu_X(dx)g(x), \end{align*} which is what you wanted, I hope.