While both are 5.4L engines, there's no guarantee a 1998 F-150 5.4L engine will be a direct bolt-in replacement for a 1999 Expedition 5.4L engine. There are subtle differences between engine variants across model years and even between trucks and SUVs. Things like the engine's accessories (alternator, power steering pump mounting, etc.), computer control modules (PCM), and even minor internal differences could cause compatibility issues.
You'd need to verify the engine codes to see how closely they match. Even with matching codes, you could still run into issues with wiring harnesses and mounting points. It's best to consult a Ford parts catalog or a mechanic specializing in Ford vehicles to determine compatibility before attempting the swap. A seemingly small incompatibility could lead to a significant headache and potentially costly repairs.