EGA IV$_4$, 19.3.8 (and 19.3.6); this addresses openness upstairs without properness, and (as an immediate consequence) the openness downstairs if $f$ is proper (which I assume you meant to require).
The general intuition is that openness holds upstairs for many properties, and so then holds downstairs when map is proper. As for proving openness upstairs, the rough idea is to first prove constructibility results, and then refine to openness by using behavior under generization. But it's a long story, since there are many kinds of properties one can imagine wanting to deal with. These sorts of things are developed in an extraordinarily systematic and comprehensive manner in EGA IV$_3$, sections 9, 11, 12 (especially section 12 for the niftiest stuff).