How do I find closed form for $\int|\cos x|\,dx$ for all real $x$?
It can be expressed as incomplete elliptic integral of the second kind:
$$\int|\cos x|\,dx=\int\sqrt{1-1^2\sin^2x}\,dx=E(x,1)$$
However, I feel that form without special function exists, because definite integral can be computed using only elementary functions by dividing it into several integrals.


Experimenting, I found following:
$$\int |\cos x| \, dx=\sin x\,\text{sgn}(\cos x)+\left\lfloor\frac{x}{\pi}+\frac{1}{2}\right\rfloor+\left\lceil\frac{x}{\pi}-\frac{1}{2}\right\rceil+C$$
Floor and ceiling functions are required to make antiderivative continuous everywhere. Then it can be used to get correct results when using this antiderivative in definite integral calculation such as:
$$\int_0^{12\pi}|\cos (x)|\,dx=24$$
Without floor and ceiling part we would get $0$ which is obviously incorrect.
To prove that given function is correct antiderivative, just differentiate it. Note that floor, ceiling and signum functions have derivative $0$ (where it's defined). To prove that it indeed is continuous, first note, that cosine is continuous everywhere, signum is continuous everywhere except at $0$ and floor and ceiling functions are continuous everywhere except at integers. Then $\text{sgn}(\cos x)$ is discontinuous where cosine is $0$, that is $x=\frac{\pi}{2}+ \pi n,n\in\mathbb{Z}$. It happens that floor and ceiling functions here are discontinuous at the same exact points. To prove that whole function is continuous, values and left and right limits at those points should be evaluated and be the same.
Value at $x=\frac{\pi}{2}+\pi n$:
$$\sin \left(\frac{\pi}{2}+ \pi n\right)\,\text{sgn}\left(\cos \left(\frac{\pi}{2}+ \pi n\right)\right)+\left\lfloor\frac{\frac{\pi}{2}+ \pi n}{\pi}+\frac{1}{2}\right\rfloor+\left\lceil\frac{\frac{\pi}{2}+ \pi n}{\pi}-\frac{1}{2}\right\rceil=$$ $$=0+(n+1)+n=2n+1$$
Limit at same $x$: $$\lim_{x\to\frac{\pi}{2}+\pi n}\left(\sin x\,\text{sgn}(\cos x)+\left\lfloor\frac{x}{\pi}+\frac{1}{2}\right\rfloor+\left\lceil\frac{x}{\pi}-\frac{1}{2}\right\rceil\right)=$$
$$=\lim_{\epsilon\to 0}\left(\sin \left(\frac{\pi}{2}+ \pi n+\epsilon\right)\,\text{sgn}\left(\cos \left(\frac{\pi}{2}+ \pi n+\epsilon\right)\right)+\left\lfloor\frac{\frac{\pi}{2}+ \pi n+\epsilon}{\pi}+\frac{1}{2}\right\rfloor+\left\lceil\frac{\frac{\pi}{2}+ \pi n+\epsilon}{\pi}-\frac{1}{2}\right\rceil\right)=$$
$$=\lim_{\epsilon\to 0}\left(\cos \left(\pi n+\epsilon\right)\,\text{sgn}\left(-\sin\left(\pi n+\epsilon\right)\right)+\left\lfloor n+1+\frac{\epsilon}{\pi}\right\rfloor+\left\lceil n+\frac{\epsilon}{\pi}\right\rceil\right)=$$
$$=2n+1+\lim_{\epsilon\to 0}\left((-1)^n\cos\epsilon\,\text{sgn}\left(-(-1)^n\sin\epsilon\right)+\left\lfloor\frac{\epsilon}{\pi}\right\rfloor+\left\lceil\frac{\epsilon}{\pi}\right\rceil\right)=$$
$$=2n+1+\lim_{\epsilon\to 0}\left(-\text{sgn }\epsilon+\left\lfloor\frac{\epsilon}{\pi}\right\rfloor+\left\lceil\frac{\epsilon}{\pi}\right\rceil\right)$$
Now consider left and right limits separately:
$$\lim_{\epsilon\to 0^-}\left(-\text{sgn }\epsilon+\left\lfloor\frac{\epsilon}{\pi}\right\rfloor+\left\lceil\frac{\epsilon}{\pi}\right\rceil\right)=-(-1)+(-1)+0=0$$
$$\lim_{\epsilon\to 0^+}\left(-\text{sgn }\epsilon+\left\lfloor\frac{\epsilon}{\pi}\right\rfloor+\left\lceil\frac{\epsilon}{\pi}\right\rceil\right)=-1+0+1=0$$
They are equal, that means limit at $x$ exists, also this limit is equal to function value at same point, so function is continuous at $x$ and, putting all together, we know that function is continuous everywhere.
Also, note that this function can be used to find $\int |\sin x| \, dx=\int |\cos(x-\frac{\pi}{2})| \, dx$
Thanks @darya khosrotash for comment and @UserX for partial answer, as well as @Barry Cipra for pointing out that previous version of this answer was not continuous everywhere.