  Probing the structures of stellar winds is of prime importance for the
understanding of massive stars. Based on their optical spectral morphology and
variability, the stars of the Oef class have been suggested to feature
large-scale structures in their wind. High-resolution X-ray spectroscopy and
time-series of X-ray observations of presumably-single O-type stars can help us
understand the physics of their stellar winds. We have collected XMM-Newton
observations and coordinated optical spectroscopy of the O6Ief star lambda Cep
to study its X-ray and optical variability and to analyse its high-resolution
X-ray spectrum. We investigate the line profile variability of the He II 4686
and H-alpha emission lines in our time series of optical spectra, including a
search for periodicities. We further discuss the variability of the broadband
X-ray flux and analyse the high-resolution spectrum of lambda Cep using
line-by-line fits as well as a code designed to fit the full high-resolution
X-ray spectrum consistently. During our observing campaign, the He II 4686 line
varies on a timescale of ~18 hours. On the contrary, the H-alpha line profile
displays a modulation on a timescale of 4.1 days which is likely the rotation
period of the star. The X-ray flux varies on time-scales of days and could in
fact be modulated by the same 4.1 days period as H-alpha, although both
variations are shifted in phase. The high-resolution X-ray spectrum reveals
broad and skewed emission lines as expected for the X-ray emission from a
distribution of wind-embedded shocks. Most of the X-ray emission arises within
less than 2R* above the photosphere.
