When the switch goes off you need to record the value of millis() into an unsigned long variable - let's call it startMillis.
Then each iteration of loop() you need to check
if (millis() - startMillis >= interval) {
// switch stuff off
}
The variable "interval" holds the number of milliseconds that the fan should stay on after the switch is turned off.
...R