[Can I] apply for ESTA before I leave for Canada as it would save time and I would be less anxious
Yes.
J1 and ESTA at the same time, if I apply now.
ESTA is not an immigration status. It is somewhat like a visa because it is an authorization to apply for admission at the border. If the ESTA is granted while you are in the US, there will be no change to your J-1 immigration status.
You will have a valid J-1 visa and a valid ESTA, which means that when you return to the US you can apply for admission either in J-1 status or in one of the visa waiver program statuses (WB for business visitors and WT for others). If you are not eligible to enter the US in J-1 status, for example because your program has ended, then that isn't an option, and you would only be able to enter as a VWP visitor.
My passport validity is 5 months and some days. Wanted to reconfirm if there will be any issues on both sides, Canada and USA.
This should be fine. The US will not admit you beyond the expiration date of your passport (because Portugal is a member of the "six-month club"). I believe the same is true of Canada, but I am not certain. I do know that (the last time I checked, at least) Canada has no minimum validity requirement. If you are planning to have left both countries by the time your passport expires, there should be no problem.