We study the connection between the Hilbert-Schmidt measure of entanglement
(that is the minimal distance of an entangled state to the set of separable
states) and entanglement witness in terms of a generalized Bell inequality
which distinguishes between entangled and separable states. A method for
checking the nearest separable state to a given entangled one is presented. We
illustrate the general results by considering isotropic states, in particular
2-qubit and 2-qutrit states -- and their generalizations to arbitrary
dimensions -- where we calculate the optimal entanglement witnesses explicitly.