Economic analysis addresses risk and long-term issues with discounted expected utility, focusing on optimality. Viability theory is based on sustainability constraints to be satisfied over time, focusing on feasibility. We make a bridge between these two approaches by showing that viability is equivalent to an array of degenerate intertemporal optimization problems. This makes the approach more interpretable in economic terms, and especially regarding efficiency. First, the deterministic case is examined. A particular emphasis is put on the connections between the viability kernel and the minimal time of crisis function. Then, we present stochastic viability with the notions of viable scenario and maximal viability probability. We show that the maximal viability probability shares dynamic programming properties with optimal discounted expected utility. Thus, both exhibit time-consistency, which may be a basis for an axiomatization of criteria under risk and long run for public decision-making.