$\hat{e}_R$ is the unit radial vector. This is simply $(x,y,z)$ divided by its length, $r$: $\hat{e}_R=\frac{(x,y,z)}{r}$.
$\hat{e}_\theta$ is the unit vector tangent to the sphere, thus perpendicular to $(x,y,z)$, which is also perpendicular to $(0,0,1)$ since changing $\theta$ does not change $z$. Therefore, we simply need to take the cross product of $(x,y,z)$ and $(0,0,1)$ and normalize to get $\hat{e}_\theta=\frac{(-y,x,0)}{\sqrt{r^2-z^2}}$. The sign is chosen so that the vector points counter-clockwise.
$\hat{e}_\phi$ is perpendicular to the other two, so we take the cross product and normalize: $\hat{e}_\phi=\frac{(-xz,-yz,r^2-z^2)}{r\sqrt{r^2-z^2}}$. Again, the sign is chosen to have positive $z$ component.
Thus, we get
$$
\begin{align}
\hat{e}_R&=\frac{(x,y,z)}{r}\\
\hat{e}_\theta&=\frac{(-y,x,0)}{\sqrt{r^2-z^2}}\\
\hat{e}_\phi&=\frac{(-xz,-yz,r^2-z^2)}{r\sqrt{r^2-z^2}}
\end{align}
$$
References
- Source of the polar-coordinate image here from Wikipedia.
According to Wikipedia, the $\hat{\phi}$ components of $\hat{\imath}$ and $\hat{\jmath}$ are, respectively, $-\sin\phi$ and $\cos\phi$; that is,
\begin{align*}
\hat{\imath} &= (\sin{\theta} \cos{\phi} )\hat{r} + (\cos{\theta} \cos{\phi})\hat{\theta} - (\sin{\phi})\hat{\phi}, \\
\hat{\jmath} &= (\sin{\theta} \sin{\phi} )\hat{r} + (\cos{\theta} \sin{\phi})\hat{\theta} + (\cos{\phi})\hat{\phi}, \\
\hat{k} &= (\cos{\theta}) \hat{r} - (\sin{\theta})\hat{\theta}.
\end{align*}
Best Answer
Another way to see the relation:
$\vec r=x\hat x+y\hat y$
$\hat r=\dfrac{\partial\vec r}{\partial r}/\left|\dfrac{\partial\vec r}{\partial r}\right|=\cos\phi\hat x+\sin\phi\hat y$$
$\hat\phi=\dfrac{\partial\vec r}{\partial\phi}/\left|\dfrac{\partial\vec r}{\partial\phi}\right|=(-r\sin\phi\hat x+r\cos\phi\hat y)/r=-\sin\phi\hat x+\cos\phi\hat y$