I have to agree with dclagett. The discovery work in an engine refit can be expensive. It normally is not a plug and play. Shaft size ,shaft angle, larger thru hull for cooling, Propping, wiring and controls, exhaust configuration, engine bed clearances. The list can go on and even the best marine technician will not find the issue until he gets to it. Many times this requires 1 step forward and two steps back at $100.00 per hour labor +. Most of the control cabling is installed in a boat before the deck goes on. The engine is installed before the deck goes on. Everything is in place and it is plug and play. This is not the case on an engine refit. I have done a few gas powered conversions to diesel in larger boats. The jobs were successful and customers were happy with the boats performance. It did take them a while to justify the cost. I'm not sure they ever did come to terms with that. It was expensive and the cost of Labor was much higher than you would think. I have done many engine replacements of the same manufacture and same power plant because of engine failures or freeze damage. The in like kind engine replacements are usually plug and play. This is by far the better way to go.
The D4 is a good engine. The Yanmar is too so your not really going for better quality just apples to apples in my opinion. The one item that you should address regardless of which engine you go with is the Seawater thru hull, strainer and plumbing. Install a larger size. In my opinion all Rangers and Cutwaters are running minimum sized raw water plumbing. My Cutwater ran 20F warmer at 3600 to 4000 rpm than 2200 rpm. It should not change more than 5F from idle to WOT when an engine reaches running temperature controlled by a thermostats. If it does there is something wrong.I have a pair of 4LHA STP Yanmars in my 34 Pilot. After reaching thermostat operating temperature, at idle, 1200 rpm,1800 rpm, 2600 rpm, 2900 rpm they are running at 175F. When I push the throttles to Max 3400 the temps climb 5F to 180 and it just stay's there moving slightly cooler then back to 180F. 1 1/2" thru hull and plumbing is the minimum recommendation for 150 hp or higher in my opinion.