5. Let $a$ be a real number, and the equation with respect to $x$
$$
(a+\cos x)(a-\sin x)=1
$$

has real roots. Then the range of values for $a$ is
5. $\left[-1-\frac{\sqrt{2}}{2},-1+\frac{\sqrt{2}}{2}\right] \cup\left[1-\frac{\sqrt{2}}{2}, 1+\frac{\sqrt{2}}{2}\right]$. Let $u=a+\cos x, v=a-\sin x$.
The equation has real roots
$\Leftrightarrow$ the hyperbola $w v=1$ intersects the circle $(u-a)^{2}+(v-a)^{2}=1$.

Notice that, the center of the circle lies on the line $y=x$, so we only need to find the position of the center when the circle is tangent to the hyperbola.
When the circle is tangent to the hyperbola at point $A(1,1)$,
$$
a=1 \pm \frac{\sqrt{2}}{2} \text {. }
$$

When the circle is tangent to the hyperbola at point $B(-1,-1)$,
$$
a=-1 \pm \frac{\sqrt{2}}{2} \text {. }
$$

Therefore, the range of $a$ is
$$
\left[-1-\frac{\sqrt{2}}{2},-1+\frac{\sqrt{2}}{2}\right] \cup\left[1-\frac{\sqrt{2}}{2}, 1+\frac{\sqrt{2}}{2}\right] \text {. }
$$