Sufficient and necessary conditions to get an infinite fiber $g^{-1}(w)$ I want to verify the proof of this result and get some start ideas to overcome the different steps of this proof.
Lemma: Let $g$ be a real analytic function. Then we have the equivalence $((a)∧(b))⇔(c)$, where the statements $(a),(b)$ and $(c)$ are given by:
(a) $g$ has infinitely many real zeros and the set of those zeros is unbounded in both directions.
(b) $g$ assumes arbitrarily large and arbitrarily small values, i.e., for all $K>0$, there are $s_1,s_2$ with $g(s_1)<-K$ and $g(s_2)>K$,
(c) The fiber $g^{-1}(w)$ is infinite for all $w∈ℝ$.
Proof: (1) To prove that $(a)∧(b)⇒(c)$, assume by contraduction that the equation $g(s)=w$ has only finitely many solutions $(b_{j})_{1≤j≤i}$. That means there are $z_1<z_2$ such that $g(s)≠w$ for $w<z_1$ or $w>z_2$. Let $z_3$ be the largest zero of $g$ smaller than $z_1$, and $z_4$ the smallest zero larger than $z_2$. The existence of $z_3$ and $z_4$ is guaranteed by item (a) and the fact that $g$ is analytic, so $g$ has only finitely many zeros in the compact interval $[z_1,z_2]$ (or $g$ is identically $0$, but that has been ruled out by the premise that it take arbitrarily large values), hence there must be infinitely many outside the interval. Let $K=\max({|g(s)|:z_3≤s≤z_4})+|w|$. By assumption, there are $s_1,s_2$ with $ g(s_1)<-K$ and $g(s_2)>K$. By the intermediate value theorem, there is an $s_{w}$ between $z_3$ or $z_4$ and $s_1$ or $s_2$ with $g(s_{w})=w$. Contradiction.
We note that if $g$ is not analytic then it satisfies conditions (a) and (b) but does not satisfy (c). 
(2) To prove that $(c)⇒(a)∧(b)$, we note first that $g$ has infinitely many zeros because the fiber $g^{-1}(0)$ is infinite. This proves item (a). To prove item (b), let $K>0$ and $w=K+ε,ε>0$. The fiber $g^{-1}(K+ε)$ is nonempty because it is infinite, hence there is $s_2$ such that $g(s_2)=w=K+ε>K$. By the same method, $g^{-1}(-K-ε)$ is nonempty, so there is $s_1$ such that $g(s_1)=-K-ε<-K$.
 A: It turns out that both versions of this Lemma are, in fact, false. Only one direction of the desired dual implication holds in each case.


Lemma (First Version): Let $g$ be a real analytic function. Then we have the equivalence $((a)∧(b))⇔(c)$, where the statements $(a),(b)$ and $(c)$ are given by:
(a) $g$ has infinitely many real zeros.
(b) $g$ assumes arbitrarily large and arbitrarily small values, i.e., for all $K>0$, there are $s_1,s_2$ with $g(s_1)<-K$ and $g(s_2)>K$.
(c) The fiber $g^{-1}(w)$ is infinite for all $w∈ℝ$.

As pointed out in the comments, the function $g(x)=x^2\sin^2(x)-e^x$ is a real-analytic function having infinitely-many real zeros, and which assumes arbitrarily large positive and negative values. However, for example, the fiber $g^{-1}(-10)$ is a singleton. Hence, the implication $\bigl((a)\wedge(b)\bigr)\implies(c)$ fails.
However, the implication $(c)\implies\bigl((a)\wedge(b)\bigr)$ readily holds. Since all real fibers are infinite, then $g$ assumes arbitrarily large positive and negative values, and has infinitely-many real zeroes.


Lemma (Second Version): Let $g$ be a real analytic function. Then we have the equivalence $((a)∧(b))⇔(c)$, where the statements $(a),(b)$ and $(c)$ are given by:
(a) $g$ has infinitely many real zeros and the set of zeros is unbounded in both directions.
(b) $g$ assumes arbitrarily large and arbitrarily small values, i.e., for all $K>0$, there are $s_1,s_2$ with $g(s_1)<-K$ and $g(s_2)>K$.
(c) The fiber $g^{-1}(w)$ is infinite for all $w∈ℝ$.

Consider the function $g(x)=1+e^x\sin x.$ This is a real-analytic function with every fiber infinite, taking on arbitrarily large positive and negative values, and for which there are infinitely-many zeroes, but the set of zeroes is unbounded in one direction only. Hence, the implication $(c)\implies\bigl((a)\wedge(b)\bigr)$ fails.
I will now go through your proof attempt and point out places where your reasoning fails or needs work.

Proof: (1) To prove that $(a)∧(b)⇒(c)$, assume by contraduction that the equation $g(s)=w$ has only finitely many solutions $(b_{j})_{1≤j≤i}$. That means there are $z_1<z_2$ such that $g(s)≠w$ for $w<z_1$ or $w>z_2$. Let $z_3$ be the largest zero of $g$ smaller than $z_1$, and $z_4$ the smallest zero larger than $z_2$. The existence of $z_3$ and $z_4$ is guaranteed by item (a) and the fact that $g$ is analytic, so $g$ has only finitely many zeros in the compact interval $[z_1,z_2]$ (or $g$ is identically $0$, but that has been ruled out by the premise that it take arbitrarily large values), hence there must be infinitely many outside the interval.

You're close, here, but not quite done. Since the set of zeros of $g$ is unbounded in both directions, then there is a zero of $g$ that is less than $z_1$ and there is a zero of $g$ that is greater than $z_2$--call them $z_-,z_+,$ respectively. We know that $g$ is not identically zero since it takes on arbitrarily large positive and negative values, so real analyticity guarantees that there are only finitely-many zeros of $g$ in any compact interval. In particular, there are only finitely-many zeroes in the intervals $[z_-,z_1]$ and $[z_2,z_+],$ and at least one in each. Hence, there exist $z_3,z_4$ as you described. Without using analyticity in this fashion, there need be no greatest zero of $g$ less than $z_1,$ nor a least zero of $g$ greater than $z_2.$ We know that there are infinitely-many zeros outside of $[z_1,z_2]$ by $(a)$ alone, with no need to reference analyticity.

Let $K=\max({|g(s)|:z_3≤s≤z_4})+|w|$. By assumption, there are $s_1,s_2$ with $ g(s_1)<-K$ and $g(s_2)>K$. By the intermediate value theorem, there is an $s_{w}$ between $z_3$ or $z_4$ and $s_1$ or $s_2$ with $g(s_{w})=w$. Contradiction.

It's possible that this does the trick, but it isn't at all clear why it should. To make this rigorous, we would probably need to consider several cases, depending on where $s_1,s_2$ fell on the real line with respect to each other and to $z_1,z_2,z_3,z_4.$ That would be prohibitively time-consuming, though, and may not even yield the desired result! I offer an alternative approach below.

We note that if $g$ is not analytic then it satisfies conditions (a) and (b) but does not satisfy (c).

This note is not only irrelevant, it is false. Functions that are not analytic can satisfy any of the following:

*

*None of (a),(b),(c). Consider $g(x)=1+\chi_{\Bbb Q}(x)\arctan(x)$, where $\chi_A$ denotes the indicator function of the set $A$.

*(a) only. Consider $g(x)=\chi_{\Bbb Q}(x)$

*(b) only. Consider $g(x)=1+\chi_{\Bbb Q}(x)x.$

*(b) and (c), but not (a). Consider $g(x)=x^3\sin(x)\chi_{\Bbb R\setminus A}(x)+\chi_A(x),$ where $A$ is the set of positive zeros of the sine function.

*(a) and (b), but not (c). Consider $g(x)=\chi_{\Bbb Q}(x)x.$

*(a), (b), and (c). Consider $g(x)=\tan(x)\left(1-\chi_{\Bbb Q\cap\left(-\frac\pi2,\frac\pi2\right)}(x)\right).$

(2) To prove that $(c)⇒(a)∧(b)$, we note first that $g$ has infinitely many zeros because the fiber $g^{-1}(0)$ is infinite. This proves item (a).

It doesn't prove item (a), and can't, as the example $g(x)=1+e^x\sin x$ shows. We can conclude that the set of zeros of $g$ is unbounded, but we cannot conclude that it is unbounded in both directions.
Your proof that $(c)\implies(b)$ is fine.

Here is an outline of an alternative proof of the implication $\bigl((a)\wedge(b)\bigr)\implies(c)$ in the second version of the Lemma.
Proof Outline: First, note that the set of real zeros of $g$ is a discrete set (any bounded interval contains only finitely-many of them) that is unbounded in both directions. Hence, we can index the real zeros in order by the integers--that is, the set of zeroes is $$\{z_n:n\in\Bbb Z\}$$ where $z_n<z_{n+1}$ for all $n\in\Bbb Z$.
Next, note that by Intermediate Value Theorem, we have for each $n\in\Bbb Z$ that $g(z)$ has the same sign for all $z\in(z_n,z_{n+1}).$ It then follows by Extreme Value Theorem that for each $n$ there is a non-zero $v_n$ such that

*

*$v_n\le g(z)<0$ for all $z\in(z_n,z_{n+1})$ if $v_n<0,$ and there is some $z'_n\in(z_n,z_{n+1})$ for which $g(z'_n)=v_n$.

*$v_n\ge g(z)>0$ for all $z\in(z_n,z_{n+1})$ if $v_n>0,$ and there is some $z'_n\in(z_n,z_{n+1})$ for which $g(z'_n)=v_n$.

Now, note that $\{v_n:n\in\Bbb Z\}$ is unbounded above and below. Indeed, if it were bounded above or below, then by definition of the $v_n,$ $g$ could not assume arbitrarily large positive and negative values.
Finally, since we already know that $g^{-1}(0)=\{z_n:n\in\Bbb Z\}$ is infinite, then take any non-$0$ $w\in\Bbb R.$ If $w<0,$ then there are infinitely-many $n$ for which $v_n<w,$ so by Intermediate Value Theorem and by definition of the $v_n,$ we have that $g^{-1}(w)$ is infinite. We similarly have that $g^{-1}(w)$ is infinite if $w>0.$ $\Box$

Addendum: I think that the closest you're going to come to salvaging the Lemma is as follows.

Lemma (Suggested Version): Let $g$ be a real analytic function, with the set of real zeroes of $g$ unbounded in both directions (so necessarily infinite). Then the following are equivalent:

*

*$g$ assumes arbitrarily large and arbitrarily small values, i.e., for
all $K>0$, there are $s_1,s_2$ with $g(s_1)<-K$ and $g(s_2)>K$.

*The fiber $g^{-1}(w)$ is infinite for all $w∈ℝ$.


As we've seen, the latter readily implies the former, and we can prove the latter from the former using the proof outline above.
