Cloud-Fog Radio Access Networks (CF-RAN) were proposed as an alternative network architecture to alleviate the high fronthaul capacity requested in traditional Cloud RAN (CRAN) by moving some BaseBand Units (BBUs) from the cloud nodes to fog nodes closer to users. However, when BBU processing is moved into fog nodes, OPEX and CAPEX will increase, and the cost and energy savings introduced by CRAN will also reduce. Moreover, mobile traffic fluctuations may lead to an unbalanced resource utilization and energy-inefficient operation in fog nodes. To address this problem, processing functions in fog nodes could be activated and deactivated in function of network traffic and BBUs placed on fog nodes could be migrated to cloud nodes when network traffic is low. In this paper, we propose an Integer Linear Programming (ILP) formulation to address this dynamic resource allocation problem. By means of Network Functions Virtualization (NFV), virtualized BBUs (vBBUs) can be dynamically allocated and deallocated in fog nodes. Furthermore, considering the availability of cloud nodes and the optical fronthaul, vBBUs can be migrated from fog nodes to cloud nodes in order to balance processing loads and save energy. Compared to a baseline incremental algorithm without vBBU migration, our proposal reduces blocking probability in 89% and achieves power savings of 38%, while providing a very small rate of service interruption due to vBBUs migration.