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)

Relevant cards

Note: All applicable cards may not be listed below.
SV2_5
SV2_5