Solitary waves in the nonlinear wave equation and in gauge theories