Within an advanced Langevin-hydrodynamics framework coupled to a hybrid fragmentation-coalescence hadronization model, we study heavy flavor quenching and flow in relativistic heavy-ion collisions. We investigate how the initial heavy quark spectrum, the energy loss and hadronization mechanisms of heavy quarks in medium, the evolution profile of pre-equilibrium stage, the flow of medium and the temperature dependence of heavy quark diffusion coefficient influence the suppression and elliptic flow of heavy mesons at RHIC and the LHC. Our result shows that different modeling of initial conditions, pre-equilibrium evolution and in-medium interaction can individually yield about 10-40% uncertainties in D meson suppression and flow at low transverse momentum. We also find that a proper combination of collisional versus radiative energy loss, coalescence versus fragmentation in hadronization, and the inclusion of medium flow are the most important factors for describing the suppression and elliptic flow of heavy mesons.