Yes, you have to apply for the work and residency permits before applying for the Sweden D Visa. The Sweden D visa authorizes log stays in the country but does not authorize employment or residing in the country.