Resonant magnetic perturbation (RMP) and error field correction (EFC) produced by toroidally and poloidally distributed coil systems can be optimized if each coil is powered with an independent power supply. A 3D multi-mode geometry-independent Lagrange method has been developed and appears to be an efficient way to minimize the parasitic spatial modes of the magnetic perturbation and the coil current requirements while imposing the amplitude and phase of a number of target modes. A figure of merit measuring the quality of a perturbation spectrum with respect to RMP independently of the considered coil system or plasma equilibrium is proposed. To ease the application of the Lagrange method, a spectral characterization of the system, based on a generalized discrete Fourier transform applied in current space, is performed to determine how spectral degeneracy and side-band creation limit the set of simultaneously controllable target modes. This characterization is also useful to quantify the efficiency of the coil system in each toroidal mode number and to know whether optimization is possible for a given number of target modes. The efficiency of the method is demonstrated in the special case of a multipurpose saddle coil system proposed as part of a future upgrade of Tokamak à Configuration Variable (TCV). This system consists of three rows of eight internal coils, each coil having independent power supplies, and provides simultaneously EFC, RMP and fast vertical position control.