Is it possible to power a 6V motor from a 24V battery if I switch on an off the power with a certain frequency and filling factor.
If yes, how can I calculate the optimum frequency and filling factor of the PWM signal that drives the switch?

I mean the duty cycle and frequency for which the motor reaches an efficiency as close as possible to that of the case when it is powered from a 6V battery.

That's been answered by retrolefty - 25% - well that's a good starting point as it depends on PWM rate and how the free-wheeling is done. If you are using a half-H-bridge switching from +24V to 0V then the behaviour in theory is linear with duty cycle. However real-world behaviour won't be perfect.

Honestly, that 25% duty cycle seemed to me a miscalculation done by somebody that took a pure resistive load as model but overlooked the fact that P in not U/R but U^2/R.

In general, motors don't want very high pwm. I would stay within 1khz if I were you.

I will also add that much more than 4x energy goes into the motor at 24v than at 6v, particularly when the motor is revolving at speed closer to its no-load rpm at 6v. As such, I would put 25% @ 24v as the upper end as an approximation to 100% @ 6v.

If you want to find out the exact answer, you may have to experiment.

Consider the inductance is L, a parameter, and calculate duty_cycle_optimum and f_optimum as a function of L. That would be much more useful for me because the results can be easily particularized to any motor as soon as I find its inductance.

I would suggest you figure this out empirically. Attach a load to your motor -- like a propeller or something -- and run it from 6V. Measure the RPM and current draw.
Now run it from PWM 24V and finesse the duty cycle and frequency until you reach a similar RPM and current draw.