If you are hired to write a composition and create a track. That is a "Work for Hire" and like every other job if they hire you they get the work. A standard deal for film and TV is that they own the recording 100% and the composition and publishing 100% but they grant back 100% of the composition royalties (NOT publishing or recording ownership) back to the composer. You should try to get this type of deal.
If a commercial wants to use a composition and recording you already created you keep all ownership. You are granting a license for them to use your music. If it's enough money they will ask for an exclusive at least in the same product line. (No other car commercials for a period of 24 months etc...)