Laplace equation in spherical coordinates
First we need to understand where spherical harmonics come from. The spherical harmonics come from the solutions of the Laplace equation in the spherical coordinates by the separation of variables.
The solution has the general form:
$$
V(r, \theta, \varphi) = R(r)\Theta(\theta)\Phi(\varphi)
$$
For each of the components $R(r)$, $\Theta(\theta)$, $\Phi(\varphi)$ we have separate ordinary differential equation with the following solutions
$$
R(r) \rightarrow A_{lm} r^l + \frac{B_{lm}}{r^{l+1}}
$$
$$
\Theta(\theta) \rightarrow P_l^m(\cos\theta)
$$
$$
\Phi(\varphi) \rightarrow e^{im\varphi}
$$
Combining all together we get
$$
V(r, \theta, \varphi) =
\sum_{l=0}^{\infty}
\sum_{m=-l}^{l}
\left( A_{lm}r^l + \frac{B_{lm}}{r^{l+1}} \right)
P_l^m(\cos \theta)
e^{im\varphi} =
\sum_{l=0}^{\infty}
\sum_{m=-l}^{l}
\left( A_{lm}r^l + \frac{B_{lm}}{r^{l+1}} \right)
Y_l^m(\theta, \varphi)
$$
where $Y_l^m(\theta, \varphi)$ is the complex spherical harmonics
Ordinary differential equation for the $\Phi(\varphi)$
Now let us look at the details for the ordinary differential equation for the component $\Phi(\varphi)$. This is the simplest form of the wave equation:
$$
\frac{1}{\Phi}\frac{d^2 \Phi}{d\varphi^2} = -m^2
$$
The solution is well known and may be defined either as a complex function
$$
\Phi(\varphi) = A_me^{im\varphi}
$$
or as a combination of real sinus and cosines functions
$$
\Phi(\varphi) = C \sin m \varphi + D \cos m \varphi
$$
If we use the complex solution we get the complex spherical harmonics. If we use the real sin/cos solutions we get the real spherical harmonics.
How to convert complex spherical harmonics to real harmonics
To convert complex spherical harmonics to the real one we need to convert
$$
A_m e^{im\varphi} \rightarrow C \sin m \varphi + D \cos m \varphi
$$
By the Euler formula:
$$
Z = A e^{im\varphi} = A (\cos\varphi + i \sin \varphi)
$$
$$
Z^* = A e^{-im\varphi} = A (\cos\varphi - i \sin \varphi)
$$
It means
$$
A \cos \varphi = \frac{Z + Z^*}{2}
$$
$$
A \sin \varphi = \frac{Z - Z^*}{2 i}
$$
This definition is near the same as you write for real harmonics in the initial question. But we need to scale it by the some normalization coefficient to keep orthogonality properties.