Here’s a sketch of one possible argument. Let $u=\sup_{x\in[a,b]}f(x)$. (Note that I allow the possibility that $u=\infty$.) There is a sequence $\langle x_n:n\in\Bbb N\rangle$ in $[a,b]$ such that for each $n\in\Bbb N$, $u-f(x_n)<\frac1{2^n}$ if $u\in\Bbb R$ and $f(x_n)>n$ if $u=\infty$. Extract a monotone subsequence $\langle x_{n_k}:k\in\Bbb N\rangle$. Being a monotone, bounded sequence, $\langle x_{n_k}:k\in\Bbb N\rangle$ converges to some $y$. (Note that you have to use the completeness of $\Bbb R$ in some way, and this is the most elementary that occurs to me.) Moreover, $y\in[a,b]$, and $f$ is continuous, so $f(y)=\lim\limits_{k\to\infty}f(x_{n_k})=u$.
Actually, for this question, there is no need to consider separately the cases where the function is constant vs when it isn't.
By the way, your indexing for the union is weird. It might be easier to just write it out explicitly:
\begin{equation}
\Bbb{R} = \dots \cup [x-2d, x-d] \cup [x-d, x] \cup [x, x+d] \cup [x+d, x+2d] \dots
\end{equation}
This, although tedious, gives a clear meaning of what you intend to say (and I'm sure most people will be fine with the use of $\dots$ because the intended meaning is clear). This is better than giving an incorrect statement, because currently what you have written does not make sense.
However, if you really want to write $\Bbb{R}$ as an infinite union, you could do something like:
\begin{equation}
\Bbb{R} = \bigcup_{n \in \Bbb{Z}} \left[x+nd, x+(n+1)d \right]
\end{equation}
Added Remarks:
The idea of your proof is certainly correct (and if you make the notational change I suggested above, it will certainly constitute a rigorous proof), but you should note that there is no need to consider an arbitrary $x$, simply pick $x=0$.
Best Answer
This fact is actually true even if $f$ is not continuous but attains its maximum and minimum in every closed interval (for example, $f(x)=x+\operatorname{sgn}x$).
First, notice that $f$ is injective: If we could find $x_1<x_2$ such that $f(x_1)=f(x_2)$, then $f$ would necessarily attain both its maximum and minimum in the open interval $(x_1,x_2)$.
Let $a<b<c$ in $\mathbb{R}$ be arbitrary. Let $M=\max f[a,c]$ and $m=\min f[a,c]$. Since $f$ does not attains it maximum nor its minimum in the open interval $(a,c)$, then either $(f(a),f(c))=(m,M)$ or $(f(a),f(c))=(M,m)$.
Now, let's show that the following are equivalent:
(i) $f(a)<f(b)$.
(ii) $f(b)<f(c)$.
(iii) $f(a)<f(c)$.
Finally, by changing $f$ by $-f$ is necessary, we may suppose that $f(0)<f(1)$. Let's show that $f$ is (strictly) increasing: Let $x<y$ in $\mathbb{R}$ be arbitrary. Let $K=|x|+|y|+1$. Notice that $-K<x<y<K$.
Using $a=0$, $b=1$, $c=K$ and $(i)\Rightarrow(iii)$ as above, we obtain $f(0)<f(K)$.
Using $a=-K$, $b=0$, $c=K$ and $(ii)\Rightarrow(iii)$ as above, we obtain $f(-K)<f(K)$.
Using $a=-K$, $b=x$, $c=K$ and $(iii)\Rightarrow (i)$ as above, we obtain $f(-K)<f(x)$.
Finally, using $a=-K$, $b=x$, $c=y$ and $(i)\Rightarrow(ii)$ as above, we obtain $f(x)<f(y)$.
Therefore, $f$ is strictly increasing, hence monotone.