We present a methodology to forecast mortality rates and estimate longevity and mortality risks. The methodology uses generalized dynamic factor models fitted to the differences in the log-mortality rates. We compare their prediction performance with that of models previously described in the literature, including the traditional static factor model fitted to log-mortality rates. We also construct risk measures using vine-copula simulations, which take into account the dependence between the idiosyncratic components of the mortality rates. The methodology is applied to forecast mortality rates for a population portfolio for the UK and to estimate longevity and mortality risks.