4. Let $\alpha, \beta, \gamma \in \mathbf{R}$, and satisfy
$$
\begin{array}{l}
\sin \alpha \cdot \cos \beta+|\cos \alpha \cdot \sin \beta| \\
\quad=\sin \alpha \cdot|\cos \alpha|+|\sin \alpha| \cdot \cos \beta .
\end{array}
$$

Then the minimum value of $(\tan \gamma-\sin \alpha)^{2}+(\cot \gamma-\cos \beta)^{2}$ is
$4.3-2 \sqrt{2}$.
Given the equation factorization
$(\sin \alpha-|\sin \beta|)(\cos \beta-|\cos \alpha|)=0$.
Let $x=\sin \alpha, y=\cos \beta$. Then
$\left(x-\sqrt{1-y^{2}}\right)\left(y-\sqrt{1-x^{2}}\right)=0$.
Thus, $x=\sqrt{1-y^{2}}$ or $y=\sqrt{1-x^{2}}$.
The point $(\tan \gamma, \cot \gamma)$ is on the hyperbola $x y=1$. Therefore, the required value is the square of the minimum distance between the two graphs. As shown in Figure 8, it is clear that $|A B|^{2}=\left(1-\frac{\sqrt{2}}{2}\right)^{2} \times 2=3-2 \sqrt{2}$ is the required value.