A formula for the level sets of epi-limits and some applications