You have to combine two codebases and two sets of customizations into one codebase. All your legal entities must be able to work with this codebase.
You can't do data upgrade from multiple instances to one instance. So you must do manual data import for master data and opening balances for 2 or all 4 legal entities. You can do data upgrade for one instance but since your new D365 system will have different data model than the source system (because of new codebase) you might have to resolve some issues.