Your engine placement looks to be "In-Line".
A BETA would work as a replacement for the Atomic 4 Gas engine often used in the C&C 39.
You do have 17,000 displacement. While a 40HP can work, you might find it a bit underpowered when it comes to a swift tidal current in the Pacific NW. I say that because you have identified Everett as your home port.
BETA is a good engine. The BETA 25 is listed as an Atomic 4 replacement.
betamarineusa.com
When I was looking at them, I thought the BETA 50 (45Hp) would make a good match for my 35ft 16,000 displacement boat.
Good luck with your search. Be sure that the engine will fit your space and engine stringers. If you have to modify the engine space, it will set you back almost the cost of the engine in labor and materials.