Both ferries listed are operated by the Isle of Man steam packet company. Their website page at https://www.steam-packet.com/ourports/heysham states the following for Heysham:
Heysham Port is owned and operated by Mersey Docks and Harbour Company. Heysham has limited parking facilities and Mersey Docks and Harbour Company charge £12.00 per 24 hours.
I have never got the ferry from Heysham but have used the adjacent train station irregularly. The car park is at
54.032833, -2.913083 and while I have never seen it busy (although I am only there during quiet times) it is definitely on the small side. From memory, the site is not the most secure, I believe there is an automatic barrier but there is a pedestrian gate which is left open continually to provide access to the train station, personally I'd be happy leaving a car there overnight as long as standard relativent precautions where taken such as taking (or if not, hidding) any valuables.
The companies website for their Liverpool docks says the following:
Unfortunately due to space restrictions we are unable to offer our travelling customers a car parking facility at the port. However, we have teamed up with Q-Park to offer our customers discounted parking when pre-booked online. The Q-Park Liverpool ONE car park is ideally situated just minutes away from the port and in the heart of Liverpool ONE.
Google maps estimates this as a 1/2 a mile away
However, on Q park's website the longest charge they list is for "upto 24 hours" for £18 (so £16.80 with 10% off). You may need to contact them if you wish to park for longer.
You could also consider parking your car further away and travel by public transport to the docks, but may be impractical if you have alot of luggage. There is always space at the Carton road par park near Lancaster. https://www.lancashire.gov.uk/roads-parking-and-travel/public-transport/park-and-ride/lancaster-park-and-ride/ bus 1 runs from here to China Street (about 1/4 of a mile from the train station). There is then a direct service to Heysham port station timed to meet the arrival of the boats, the train station is directly adjacent to the docks.
Alternatively in Liverpool the docks are around 1/2 from James Street staton on the Mersyrail network. services are alot more frequent then Heysham but you will need to walk this gap. You may be able to find a car park near a station furthur away from the city center. Merseyrail map: https://www.merseyrail.org/_common/map/networkmap.htm