Heavy-flavor quarks (i.e. charm and beauty) are essential probes to investigate the properties of the quark-gluon plasma (QGP) created in ultrarelativistic heavy-ion collisions. The measurement of the nuclear modification factor (RAA) gives insight into the in-medium parton energy loss in heavy-ion collisions. Furthermore, the measurements of heavy-flavor elliptic flow (v2) provide crucial information about the degree of thermalization of heavy quarks in the QGP, the path-length dependence of heavy-quark in-medium energy loss, and possible recombination effects. The higher flow harmonics, such as the triangular flow (v3), provide further constraints on the effect of fluctuations in the initial state of the system. The measurements in proton-proton (pp) collisions allow for testing perturbative quantum chromodynamics (pQCD) calculations and are needed as a baseline for investigating the medium effects in heavy-ion collisions. In this contribution, recent results of open charm and beauty production measured with the ALICE detector are discussed.