Example 6 Find the minimum value of the function $f(x)=\cos 4 x+6 \cos 3 x+17 \cos 2 x+30 \cos x, x \in \mathbf{R}$.
$$
\begin{aligned}
f(x)= & {\left[2\left(2 \cos ^{2} x-1\right)^{2}-1\right]^{2}+6\left(4 \cos ^{3} x-3 \cos x\right)+17\left(2 \cos ^{2} x-1\right)+30 \cos x } \\
= & 8 \cos ^{4} x+24 \cos ^{3} x+26 \cos ^{2} x+12 \cos x-16 \\
= & 2\left[\left(4 \cos ^{4} x+4 \cos ^{3} x+\cos ^{2} x\right)+\left(8 \cos ^{3} x+8 \cos ^{2} x+2 \cos x\right)+\left(4 \cos ^{2} x+\right.\right. \\
& 4 \cos x+1)]-18 \\
= & 2(\cos x+1)^{2}(2 \cos x+1)^{2}-18 \\
\geqslant & -18 .
\end{aligned}
$$

When and only when $\cos x=-1$ or $\cos x=-\frac{1}{2}$, the equality holds.
Therefore, the minimum value of $f(x)$ is -18.