For the domestic legs, as long as it is not a p.s.® flight you will be in the queue for complimentary upgrade, no need to do anything. It may clear anytime from T-72h right up to seconds before pushing back from the gate so if not cleared in advance do watch the screen at the gate. That is a difficult route to score complimentary upgrades; if you wish to have a confirmed upgrade you can take the offer to buy up for $450 or use some miles.
There are no complimentary upgrades on the EWR-MAD legs (barring an op-up) so if you want to sit up front you will need to shell out miles and/or $ for that.
You earn EQM based on the fare class which you purchased, not the cabin in which you actually sit. When you redeem an upgrade award for use with a purchased coach class ticket you earn at coach rates. When you take a buy-up offer you are paying additional $ to purchase the lowest available first class fare and you earn at FC rates.