Assume $f: \mathbb R \to \mathbb R$ is continuous on $\mathbb R$ and $\lim_{x \to +\infty} f(x)=0=\lim_{x \to -\infty} f(x)$ Assume $f: \mathbb R \to \mathbb R$ is continuous on $\mathbb R$ and $$\lim_{x \to +\infty} f(x)=0=\lim_{x \to -\infty} f(x)$$
Show that $f$ is bounded on $\mathbb R$ and attains either its maximum or its minimum on $\mathbb R$.

$$\lim_{x \to +\infty} f(x)=0$$
$$\iff \forall \epsilon >0(\exists a \in \mathbb R(\forall x(x> a \implies \left|f\left(x\right)\right|<\epsilon)))$$
And
$$\lim_{x \to -\infty} f(x)=0$$
$$\iff \forall \epsilon >0(\exists b \in \mathbb R(\forall x(x< b \implies \left|f\left(x\right)\right|<\epsilon)))$$
Now if for all $x \in \mathbb R:f(x)=0$ then we are done ,otherwise we are able to find a $c \in \mathbb R$ such that $f(c) \ne 0$ and setting $\epsilon \mapsto \left|f\left(c\right)\right|$ follows that exists $a<x<b$ such that $\left|f\left(x\right)\right|<\left|f\left(c\right)\right|$.
On the other hand continuity of $f$ over $\mathbb R$ implies continuity of $f$ over $[a,b]$ and by extreme value theorem $f$ attains its maximum and minimum .( I don't understand why the question say or)
But I only know that for $x \in [a,b]$ the function $f$ is bounded and  it's not enough,since the domain of $f$ is not $[a,b]$ and I need to show that for all real $x$ the function is bounded.
Besides I want to know the validity of my proof about the max-min part.
 A: Please allow me copy and modify your argument. The incorrect point in your argument is to claim that $a<b$, it should be $b<a$!

We know
\begin{align}
\lim_{x \to +\infty} f(x)=0
\iff \forall \epsilon >0(\exists a >0 (\forall x\in \mathbb R
(x> a \implies \left|f\left(x\right)\right|<\epsilon)))
\end{align}
and \begin{align}
\lim_{x \to -\infty} f(x)=0
\iff \forall \epsilon >0(\exists b<0 (\forall x\in \mathbb R
(x<b \implies \left|f\left(x\right)\right|<\epsilon))).
\end{align}
If $f(x)=0, \forall x\in \mathbb R$ then we are done.
Otherwise we are able to find a $c\in \mathbb R$ such that $f(c)\neq 0$ and setting $\epsilon:=|f(c)|$.
Thus, we conclude that for $x\in (-\infty, b)\cup(a,+\infty)$, we have $|f(x)|<\epsilon$.
On the other hand continuity of $f$ over $\mathbb R$ implies continuity of $f$ over $[a,b]$ and by extreme value theorem $f$ attains its maximum $M_{\text{max}}$ and minimum $M_{\text{min}}$ on $[a,b]$, thus bounded on $[a,b]$.
Hence $f$  is bounded on $\mathbb R$.
Regarding the maximum and minimum of $f$ on $\mathbb R$, we consider the following cases

*

*If $M_{\text{max}}>\epsilon$, then $M_{\text{max}}$ is a maximum value of $f$ on $\mathbb R$.

*If $M_{\text{min}}<-\epsilon$, then $M_{\text{min}}$ is a minimum value of $f$ on $\mathbb R$.

*Otherwise, $-\epsilon\leq M_{\text{min}} \leq M_{\text{max}}\leq \epsilon$, then $f(c)$ is a maximum if $f(c)>0$ and $f(c)$ is a minimum if $f(c)<0$.

Now, we are able to conclude that $f$  attains either its maximum or its minimum on $\mathbb R$.
A: Sometimes there is only one of max and min. Take for example  $f(x)=\frac{1}{x^2+1}$, which answers your question about "and" / "or".

Also your argumentation does not work: Every finite interval has both extrema, but they are mostly in $a$ and $b$. Now we've got the problem, because our interval is infinite and can't be approximated well enough by finite intervals.
A: Consider the one-point compactified real line $\widehat{\mathbb{R}}=\mathbb{R}\cup\infty$, where ‘$\infty$’ here denotes the identification of $+\infty$ and $-\infty$. It is clear (and in any case well-known or easy to prove) that $\widehat{\mathbb{R}}$ is topologically equivalent to the unit circle, thus it is compact. Now consider the function
$$
\hat{f}\colon \widehat{\mathbb{R}}\to\mathbb{R}\,,~\,~\,~ x\mapsto\left\lbrace
\begin{array}{ll}
f(x)&\mbox{if $x\in\mathbb{R}$}\\
0&\mbox{if $x=\infty$}
\end{array}\,.
\right.
$$
It follows, from your hypothesis, that $\hat{f}$ is continuous on the compact space $\widehat{\mathbb{R}}$, and therefore it is bounded and attains both its minimum and maximum in $\widehat{\mathbb{R}}$. Now since both extrema cannot possibly obtained at $\infty$, it follows that either one of them must be obtained in $\mathbb{R}$, as desired.
Added Later
Because the OP has provided a comment below regarding the slight advanced nature of the proof above, I’ve decided to rattle it down to a simpler one as follows: Define a new function $$g(t):=f(\frac{t}{1-|t|})\,.$$
Now it’s easy to see that the domain of $g$ is the open interval $(-1,1)$ and in particular the map $t\mapsto \frac{t}{1-|t|}$ is a one-to-one correspondence between $(-1,1)$ and $\mathbb{R}$. However, by your hypothesis on $f$ as $x\to\pm\infty$, it follows that $g$ extends to a continuous function on the closed interval $[-1,1]$ with
$$g(1):=\lim_{t\to1} f(\frac{t}{1-|t|})=0\,,~\,~\,~g(-1):=\lim_{t\to-1} f(\frac{t}{1-|t|})=0\,.$$
Thus $g$ is a continuous function on the closed bounded interval $[-1,1]$ and is therefore bounded—hence $f$ is also bounded. By the Extreme Value Theorem, $g$ attains both it’s minimum and maximum in $[-1,1]$. On the one hand, since $g(-1)=g(1)=0$, then if $0$ is simultaneously the minimum and maximum of $g$, then clearly $g(t)=0$, or equivalently, $f(x)=0$, which solves your problem trivially; on the other hand, if both extrema values are different or one of them is not $0$, then one of them is attained in $(-1,1)$ which means one of the extrema of $f$ is attained in $\mathbb{R}$.
