DMG 260 states,
When adventurers defeat one or more monsters-typically by killing, routing, or capturing them, they divide the total XP value of the monsters evenly among themselves.
The lowest level creation of undead is the "Animate Dead" spell, which states:
If you issue no commands, the creature only defends itself against hostile creatures. ... The creature is under your control for 24 hours, after which it stops obeying any command you've given it.
Thus, if you lose control of it and then attack, it defends itself, and you have yourself a fight where you can plausibly gain XP.
It's not worth it
Assuming your DM is somehow ok with this ploy, killing a zombie or skeleton nets you 50 XP. The earliest level you could do this is 5th level, where you get two spell slots to cast this spell. Assuming that you're the only one fighting the zombie/skeleton, you get an extra 100 xp a day. You need an additional 7500 XP to level up from 5 to 6, so you'd get 1.3% of a new level each day by doing this ploy, or 77 days to level up. Note that I'm describing the fastest progression--this strategy gets even less effective at any higher level. Doing this also means you can't use your 3rd level spell slots for anything else.