First, we say two intervals $A$<$B$, if $\forall a\in A, b\in B$ such that $a$<$b$, like $(-1,2]$<$(2,4]$. If $g\circ f(x)$ is increasing on A and B, then we want the image of A, B satisfying $h[A]$<$h[B]$; $f\circ g(x)$ is decreasing on $A$ and $B$, then we just have to let the image of $A, B$ satisfying $k[B]$<$k[A]$, which ensures the monotonicity (more) globally.
Give an example to show how it really works. Eventually we partition the real plain $\mathbb{R}^2$ into integer lattices. In each square, the function $f$, $g$ looks like either $\frac{1}{2}x+\frac{1}{4}$, or $-\frac{1}{2}x+\frac{3}{4}$. We should, however, shift the boxes so that we achieve what we said before.
On even-number-th interval, $f,g$ look like $-\frac{1}{2}x+\frac{3}{4}$; on odd-number-th interval, $f,g$ look like $\frac{1}{2}x+\frac{1}{4}$ inside its square. We have to map correctly from squares to squares i.e. $\mathbb{Z}\to\mathbb{Z}$ such that the local and global monotonicities are satisfied.
I.e. find two functions $i,d:\mathbb{Z}\to\mathbb{Z}$, $i$ is parity-preserving and $d$ parity-reversing, $d\circ i$ increasing, $i\circ d$ decreasing. E.g. It is not hard to check $$i(n)=\begin{cases}2n & \text{even}\\-2n+1&\text{odd}\end{cases}\quad d(n)=\begin{cases}2n+1 & \text{even}\\-2n&\text{odd}\end{cases}$$
satisfy the requirements.
These functions indicate where the squares are vertically.
Finally, put all together,
$$f(x)=\begin{cases}-\frac{1}{2}(x-\lfloor x\rfloor)+\frac{3}{4}+i(\lfloor x\rfloor) & \lfloor x\rfloor\text{ is even}\\\frac{1}{2}(x-\lfloor x\rfloor)+\frac{1}{4}+i(\lfloor x\rfloor)&\lfloor x\rfloor\text{ is odd}\end{cases}$$
$$g(x)=\begin{cases}-\frac{1}{2}(x-\lfloor x\rfloor)+\frac{3}{4}+d(\lfloor x\rfloor) & \lfloor x\rfloor\text{ is even}\\\frac{1}{2}(x-\lfloor x\rfloor)+\frac{1}{4}+d(\lfloor x\rfloor)&\lfloor x\rfloor\text{ is odd}\end{cases}$$
With the same idea, a refined solution:
First, let $f(0)=g(0)=0$. Then, we partition the axis into $\{\pm[{2^n},{2^{n+1}})\}_{n\in\mathbb{Z}}$ for $f$ and
$\{\pm[{2^n\sqrt{2}},{2^{n+1}\sqrt{2}})\}_{n\in\mathbb{Z}}$ for $g$. Then $f,g$ take value from either $\sqrt{2}x$ or $-\sqrt{2}x$ alternatingly on the partitioned intervals respectively starting to take value $\sqrt{2}x$ on $\pm[1,2)$ and $\pm[\sqrt{2},2\sqrt{2})$.