If I use Forretress ex's "Exploding Energy" Ability, can I attach any of the Energy cards that I searched for to Forretress ex before it is knocked out?
Yes. They would then be discarded with the Forretress ex.
Source: Paldea Evolved FAQ; TPCi Rules Team (2023-06-08)