An online cryogenic distillation system for the removal of krypton and radon from xenon was designed and constructed for PandaX-4T, a highly sensitive dark matter detection experiment. The krypton content in a commercial xenon product is expected to be reduced by 7 orders of magnitude with 99% xenon collection efficiency at a flow rate of 10 kg/h by design. The same system can reduce radon content in xenon by reversed operation, with an expected radon reduction factor of about 1.8 in PandaX-4T under a flow rate of 56.5 kg/h. The commissioning of this system was completed, with krypton and radon operations tested under respective working conditions. The krypton concentration of the product xenon was measured with an upper limit of 8.0 ppt.