You’ll need the motor with the computer (ecu), etc. I don’t know all the details but there are number of things regarding the physical mounting that may have changed (engine mounts, gearbox bolt pattern, etc) but equally may not have changed. Connecting the wiring will be the biggest hassle. There are a number of threads on these topics, try searching this forum (6s and 4s) for “convert”
To go further on what EBXR said, I’d suggest tracking down a wrecked XG ute because these had the 4L engine in basically the XF body (4L is externally the same as the 3.9L). Even if you don’t use the superior 4L engine, all the other bits from crossmember to dash and wiring would be useful. Also with an XG you have a good chance of finding a manual one which could be a source of a 5 speed box too.