Search for events with an isolated lepton and missing transverse momentum and a measurement of W production at HERA