https://www.boats.net/parts/search/Merc2/Mercury/40%20EFI%20%284%20CYL.%29%284-STROKE%29/0P153500%20THRU%200P400999/Cylinder%20Block%20and%20Crankcase/parts.html
https://www.boats.net/parts/search/Merc2/Mercury/50%20EFI%20%284%20CYL.%29%284-STROKE%29/0P153500%20THRU%200P400999/Cylinder%20Block%20and%20Crankcase/parts.html
Not sure if that's your 40hp or not, but to know for sure you'd better go part by part through the block & crank case diagrams fuel system and ignition component diagrams to start with. It looks like they both use the same part # for the complete cylinder head and intake manifold assemblies, which is a good sign that much will be the same.
Actually - looking quicky - they appear to be EXACTLY the same engine only the 40hp & 50hp models have a restrictor (part #24 in the
intake manifold diagram) I would imagine if they're using the same fuel injectors and same throttle body assemblies with only a restrictor to make differences in the airflow then the computer unit (ECM) controlling the injector pulse and ignition timing would be the only other difference they *should need, but I'm not going through all the diagrams to be certain.