I've spent 2 to 3 weeks in Andalucia on each of my 3 trips in the past 8 years. All my trips were in February-March but late October and into November should also be off-season. I traveled mostly by train, rented a car only for the white hill towns, because they aren't easily accessible by public transport. The trains are fast, reliable and comfortable, taking you from city center to city center. You may spend more for trains than a car would cost (including parking and gas), but you'll use up more time driving and looking for parking, plus driving in the cities is a pain.
There are a few minuses that I see in Carlos's suggestions for a first-timer - you'll have to decide how much, if at all, they would impact you. (I have put his itinerary in my files for my next visit . . . after one week in Andalucia I've been hooked on Spain). First is that you would be skipping some major sights - the Alhambra and the Mezquita. Next is that in my experience, outside the major cities (and even in parts of them) English is rarely spoken. In the places with high foreign tourist volume, sights have full explanations in English and some have audio guides. You will probably need to do more research than for a more standard/ordinary itinerary. Lastly, driving on unfamiliar roads and to remote places may not be relaxing.
Madrid - You should be able to get through the airport and to Atocha station (Madrid) by 17.00. That's plenty of time to take the train to Cordoba or Sevilla or Toledo. All are chock-full of history. You need to be in Madrid on your last night to insure getting to the airport in time. You'll need to leave Madrid around noon to be there 3 hours before your flight. If you leave all your Madrid time to the end of the trip, you avoid a hotel change. Sure, you could stay in Sevilla or Cordoba and take an early train to Madrid, but why have the stress of a possible snag that would cause you to miss your flight? If you love European painting, you need two full days to visit the 3 top art museums. For the interests you listed, there's not much in Madrid. The only thing that comes to mind is the Naval Museum (think Columbus, Pizarro, Balboa . . . ).
For the history of the Moors, Christians, Jews, my top picks are Toledo, Cordoba, Sevilla and Granada.
If you want to visit the Alhambra (the #1 sight in Spain for good reason), you should book tickets as soon as you have your dates . . . or conform your itinerary to the available dates. Right now the official website shows tickets are sold out through Nov. 3. Plan on at least 2 nights in Granada to have a full day at the Alhambra. There are still tickets available for the night visit to the Nasrid Palaces Nov. 8. I enjoyed seeing the buildings at night before my daytime visit - they look completely different and there are some views of the city below.
Sevilla is a good base for day trips to Jerez (horse shows at the Royal Equestrian School, sherry bodega tours), Cadiz, Italica (Roman ruins), and possibly Arcos. You can day trip to Cordoba but it is so rich in history and sights that you'll miss a lot without spending a couple of nights there.
I would consider renting a car in Sevilla to spend 2-3 days through the hills (staying in Ronda 2 nights or 1 there and 1 in another) and dropping it when you get to Granada.
Toledo is another good place for 2 nights. It's on a spur line from Madrid, so you have to go through Atocha station to get there. It's a half-hour train trip with frequent trains during the day