[proofplan]
The proof has two directions. If $T$ is ergodic and $f$ is an invariant measurable function, then any nontrivial Borel level set of $f$ would give a measurable set invariant modulo null sets, contradicting ergodicity. Conversely, if a nontrivial invariant set exists, its indicator function is a nonconstant invariant measurable function. The only point requiring care is that all invariance is interpreted modulo $\mathbb P$-null sets.
[/proofplan]
[step:Extract a nontrivial Borel level set from a nonconstant measurable function]
Let $f:E\to\mathbb C$ be $\mathcal E/\mathcal B(\mathbb C)$-measurable and suppose that $f$ is not equal to a constant $\mathbb P$-a.e. Define the real-valued measurable maps $u:E\to\mathbb R$ by $u(x)=\operatorname{Re}(f(x))$ and $v:E\to\mathbb R$ by $v(x)=\operatorname{Im}(f(x))$.
At least one of $u$ and $v$ is not equal to a constant $\mathbb P$-a.e.; otherwise $f=u+iv$ would be equal to a complex constant $\mathbb P$-a.e. Let $g:E\to\mathbb R$ denote one of these two functions that is not a.e. constant.
We claim that there exists $t\in\mathbb R$ such that
\begin{align*}
0<\mathbb P(\{x\in E:g(x)<t\})<1.
\end{align*}
Indeed, if no such $t$ existed, then each set $\{g<t\}$ would have probability $0$ or $1$. Define
\begin{align*}
S:=\{q\in\mathbb Q:\mathbb P(\{x\in E:g(x)<q\})=0\}.
\end{align*}
Set $a:=\sup S$. If $S$ is empty, then $\mathbb P(\{g<q\})=1$ for every $q\in\mathbb Q$. Hence the countable intersection $\bigcap_{q\in\mathbb Q}\{x\in E:g(x)<q\}$ has probability $1$, but this intersection is empty because $g$ is real-valued. If $S=\mathbb Q$, then $\mathbb P(\{g<q\})=0$ for every $q\in\mathbb Q$. Hence the countable intersection $\bigcap_{q\in\mathbb Q}\{x\in E:g(x)\ge q\}$ has probability $1$, but this intersection is empty because $g$ is real-valued. Hence $a\in\mathbb R$.
Let $q\in\mathbb Q$ satisfy $q<a$. Since $a=\sup S$, there exists $r\in S$ with $q<r\le a$. By monotonicity, $\{g<q\}\subset\{g<r\}$, so $\mathbb P(\{g<q\})=0$. Therefore
\begin{align*}
\mathbb P(\{g<a\})=0,
\end{align*}
because $\{g<a\}$ is the countable union of the sets $\{g<q\}$ over rational $q<a$. For every rational number $q>a$, the definition of $a$ gives $\mathbb P(\{g<q\})=1$, and hence
\begin{align*}
\mathbb P(\{g\ge q\})=0.
\end{align*}
Taking the countable union over rational $q>a$ gives
\begin{align*}
\mathbb P(\{g>a\})=0.
\end{align*}
Thus $\mathbb P(\{g=a\})=1$, contradicting the choice of $g$ as not a.e. constant. This proves the claim.
Choose $t\in\mathbb R$ with $0<\mathbb P(\{g<t\})<1$. If $g=u$, set $B:=\{z\in\mathbb C:\operatorname{Re}(z)<t\}$. If $g=v$, set $B:=\{z\in\mathbb C:\operatorname{Im}(z)<t\}$. In either case $B$ is a Borel subset of $\mathbb C$, and the measurable set $A:=f^{-1}(B)$ satisfies $0<\mathbb P(A)<1$.
[guided]
The goal of this step is to turn the failure of being a.e. constant into an actual measurable set of probability strictly between $0$ and $1$. Since $f$ is complex-valued, we first reduce to a real-valued function. Define
\begin{align*}
u:E&\to\mathbb R
\end{align*}
by $u(x)=\operatorname{Re}(f(x))$ and define
\begin{align*}
v:E&\to\mathbb R
\end{align*}
by $v(x)=\operatorname{Im}(f(x))$. Both maps are $\mathcal E/\mathcal B(\mathbb R)$-measurable because the real and imaginary part maps $\mathbb C\to\mathbb R$ are $\mathcal B(\mathbb C)/\mathcal B(\mathbb R)$-measurable and $f$ is $\mathcal E/\mathcal B(\mathbb C)$-measurable.
If both $u$ and $v$ were equal to constants a.e., say $u=c_1$ a.e. and $v=c_2$ a.e., then $f=c_1+ic_2$ a.e. This is excluded. Hence one of $u$ and $v$ is not equal to a constant a.e.; call that real-valued measurable function $g:E\to\mathbb R$.
We now show that some strict sublevel set of $g$ has intermediate probability. Suppose the contrary: for every $t\in\mathbb R$, the set $\{x\in E:g(x)<t\}$ has probability either $0$ or $1$. Define
\begin{align*}
a:=\sup\{q\in\mathbb Q:\mathbb P(\{x\in E:g(x)<q\})=0\}.
\end{align*}
The use of rational numbers is important because it lets us take countable unions, so countable additivity applies.
Let
\begin{align*}
S:=\{q\in\mathbb Q:\mathbb P(\{x\in E:g(x)<q\})=0\}.
\end{align*}
The set $S$ is neither empty nor all of $\mathbb Q$. If $S$ were empty, then $\mathbb P(\{g<q\})=1$ for every rational $q$. Taking the countable intersection over $q\in\mathbb Q$, the set
\begin{align*}
\bigcap_{q\in\mathbb Q}\{x\in E:g(x)<q\}
\end{align*}
would have probability $1$. But this intersection is empty: for each $x\in E$, the real number $g(x)$ is larger than some rational number. If $S=\mathbb Q$, then $\mathbb P(\{g<q\})=0$ for every rational $q$, so $\mathbb P(\{g\ge q\})=1$ for every rational $q$. Taking the countable intersection over $q\in\mathbb Q$, the set
\begin{align*}
\bigcap_{q\in\mathbb Q}\{x\in E:g(x)\ge q\}
\end{align*}
would have probability $1$. But this intersection is empty: for each $x\in E$, the real number $g(x)$ is smaller than some rational number. Thus $a=\sup S$ is a real number.
Let $q\in\mathbb Q$ satisfy $q<a$. The supremum property gives some $r\in S$ with $q<r\le a$; otherwise $q$ would be an upper bound for $S$, contradicting $q<a=\sup S$. Since $r\in S$, we have $\mathbb P(\{g<r\})=0$, and monotonicity of measure applied to $\{g<q\}\subset\{g<r\}$ gives
\begin{align*}
\mathbb P(\{g<q\})=0.
\end{align*}
Since
\begin{align*}
\{g<a\}=\bigcup_{\substack{q\in\mathbb Q, q<a}}\{g<q\},
\end{align*}
[countable subadditivity](/theorems/1108) gives
\begin{align*}
\mathbb P(\{g<a\})=0.
\end{align*}
For every rational $q>a$, the definition of $a$ gives
\begin{align*}
\mathbb P(\{g<q\})=1,
\end{align*}
and therefore
\begin{align*}
\mathbb P(\{g\ge q\})=0.
\end{align*}
Since
\begin{align*}
\{g>a\}=\bigcup_{\substack{q\in\mathbb Q, q>a}}\{g\ge q\},
\end{align*}
we obtain
\begin{align*}
\mathbb P(\{g>a\})=0.
\end{align*}
Consequently $\mathbb P(\{g=a\})=1$, so $g$ is equal to the constant $a$ a.e., contradicting the choice of $g$. Therefore there is $t\in\mathbb R$ with
\begin{align*}
0<\mathbb P(\{g<t\})<1.
\end{align*}
If $g=\operatorname{Re}(f)$, choose the Borel half-plane
\begin{align*}
B:=\{z\in\mathbb C:\operatorname{Re}(z)<t\}.
\end{align*}
If $g=\operatorname{Im}(f)$, choose the Borel half-plane
\begin{align*}
B:=\{z\in\mathbb C:\operatorname{Im}(z)<t\}.
\end{align*}
Then $A:=f^{-1}(B)$ is measurable, and by construction
\begin{align*}
0<\mathbb P(A)<1.
\end{align*}
This is the nontrivial measurable set that will contradict ergodicity once we prove it is invariant modulo null sets.
[/guided]
[/step]
[step:Show that an invariant function has invariant Borel preimages modulo null sets]
Assume that $f:E\to\mathbb C$ is $\mathcal E/\mathcal B(\mathbb C)$-measurable and satisfies $f\circ T=f$ $\mathbb P$-a.e. Define the null set $N:=\{x\in E:f(T(x))\ne f(x)\}$. Then $\mathbb P(N)=0$.
Let $B\subset\mathbb C$ be Borel and set $A:=f^{-1}(B)$. Since $f$ is measurable, $A\in\mathcal E$. For every $x\in E\setminus N$,
\begin{align*}
x\in T^{-1}(A)\iff T(x)\in A\iff f(T(x))\in B\iff f(x)\in B\iff x\in A.
\end{align*}
Hence $T^{-1}(A)\triangle A\subset N$, and therefore $\mathbb P(T^{-1}(A)\triangle A)=0$.
[/step]
[step:Use ergodicity to force invariant measurable functions to be constant]
Assume that $T$ is ergodic. Let $f:E\to\mathbb C$ be $\mathcal E/\mathcal B(\mathbb C)$-measurable and satisfy $f\circ T=f$ $\mathbb P$-a.e.
Suppose, for contradiction, that $f$ is not equal to any constant $\mathbb P$-a.e. By the first step, there exists a Borel set $B\subset\mathbb C$ such that the measurable set $A:=f^{-1}(B)$ satisfies $0<\mathbb P(A)<1$. By the second step, $\mathbb P(T^{-1}(A)\triangle A)=0$. Ergodicity then implies $\mathbb P(A)\in\{0,1\}$, contradicting the strict inequalities above. Hence $f$ is equal to a constant $\mathbb P$-a.e.
[/step]
[step:Build a nonconstant invariant function from a nontrivial invariant set]
Assume that every $\mathcal E/\mathcal B(\mathbb C)$-measurable function $f:E\to\mathbb C$ satisfying $f\circ T=f$ $\mathbb P$-a.e. is equal to a constant $\mathbb P$-a.e.
Let $A\in\mathcal E$ satisfy $\mathbb P(T^{-1}(A)\triangle A)=0$. Define the indicator function $\mathbb 1_A:E\to\mathbb C$ by $\mathbb 1_A(x)=1$ if $x\in A$ and $\mathbb 1_A(x)=0$ if $x\notin A$. Since $A\in\mathcal E$, the function $\mathbb 1_A$ is measurable.
For $x\notin T^{-1}(A)\triangle A$, membership of $x$ in $A$ is equivalent to membership of $T(x)$ in $A$, and therefore
\begin{align*}
\mathbb 1_A(T(x))=\mathbb 1_A(x).
\end{align*}
Since $\mathbb P(T^{-1}(A)\triangle A)=0$, this proves
\begin{align*}
\mathbb 1_A\circ T=\mathbb 1_A
\end{align*}
$\mathbb P$-a.e. By the hypothesis on invariant functions, $\mathbb 1_A$ is equal to a constant $\mathbb P$-a.e.
If $\mathbb 1_A=c$ $\mathbb P$-a.e. for some $c\in\mathbb C$, then $c\in\{0,1\}$. Indeed, if $c\notin\{0,1\}$, then $\mathbb 1_A(x)\ne c$ for every $x\in E$, contradicting equality a.e. If $c=0$, then $\mathbb P(A)=0$. If $c=1$, then $\mathbb P(A)=1$. Thus every invariant set modulo null sets has probability $0$ or $1$, so $T$ is ergodic.
[/step]