To help yourself and the Danish authorities, it is important that you prepare your departure, so all your commitments are terminated in time and you avoid any unpleasant bills.
When deciding to leave Denmark, you need to deregister from the Civil Registration Service. You can either deregister online or book an appointment with Viborg Municipality’s Borgerservice (Citizen Service) to deregister.
If you are renting, have children in daycare or have entered into other agreements, please note that it is very likely that there is a notice period on the agreements. Thus, make sure to terminate your agreements in time.
Regarding tax matter, please see Leaving Denmark permanently at skat.dk.
On Practical matters before leaving you can find a checklist of things to consider and sort out before leaving.