This paper deals with branching processes in varying environment, namely, whose offspring distributions depend on the generations. We provide sufficient conditions for survival or extinction which rely only on the first and second moments of the offspring distributions. These results are then applied to branching processes in varying environment with selection where every particle has a real-valued label and labels can only increase along genealogical lineages; we obtain analogous conditions for survival or extinction. These last results can be interpreted in terms of accessibility percolation on Galton-Watson trees, which represents a relevant tool for modeling the evolution of biological populations.