XMM-Newton and VLT observations of the afterglow of GRB 040827