We study stability of optimization problems in the separated locally convex topological vector space setting. We use the concepts of π-stability, dual π-stability, and π-duality gap, and establish geometric characterizations of these notions by an epigraphical analysis approach. Under a constraint qualification involving quasi relative interiors, we obtain some criteria for π-stability and π-duality gap, which are shown to be useful for obtaining relevant stability and duality theorems in infinite dimensional optimization. We apply our approach to study cone constrained problems, Fenchel duality, conjugate duality, and the subdifferentiability of functions associated with epigraphical type sets. Several duality and stability results of recent publications can be deduced from and sometimes improved by a geometric characterization of π-stability in a unifying way.