Study of W boson production in PbPb and pp collisions at sqrt(s_NN) = 2.76 TeV