A flexible importance sampling method for integrating subgrid processes