The nuclear modification factor [Formula: see text] and the azimuthal anisotropy coefficient [Formula: see text] of prompt and nonprompt (i.e. those from decays of b hadrons) [Formula: see text] mesons, measured from PbPb and pp collisions at [Formula: see text] [Formula: see text] at the LHC, are reported. The results are presented in several event centrality intervals and several kinematic regions, for transverse momenta [Formula: see text] [Formula: see text] and rapidity [Formula: see text], extending down to [Formula: see text] [Formula: see text] in the [Formula: see text] range. The [Formula: see text] of prompt [Formula: see text] is found to be nonzero, but with no strong dependence on centrality, rapidity, or [Formula: see text] over the full kinematic range studied. The measured [Formula: see text] of nonprompt [Formula: see text] is consistent with zero. The [Formula: see text] of prompt [Formula: see text] exhibits a suppression that increases from peripheral to central collisions but does not vary strongly as a function of either y or [Formula: see text] in the fiducial range. The nonprompt [Formula: see text] [Formula: see text] shows a suppression which becomes stronger as rapidity or [Formula: see text] increases. The [Formula: see text] and [Formula: see text] of open and hidden charm, and of open charm and beauty, are compared.