Jazz has a good suggestion about Toledo, but I'd want 2 nights there if it's your first stop. Otherwise, you'll basically just be recovering from the overnight flight and dealing with jetlag while you're in that wonderful city.
I don't know that it makes much difference whether your route out of Cordoba is Granada-Malaga-Seville or Malaga-Granada-Seville. Total train time is very similar, so I'd base the decision on train schedules (service in and out of Granada not being terribly frequent) and days of the week on which sights of interest to you are due to be closed.
Seville is a large city with a lot of sights, and I think you'll be very short on time there with just 3 nights. I'd extend that. By comparison, Cordoba and Granada are comparatively better covered with the time you have planned.
I'd want at least nights in Toledo even if it's not your first stop, though it's true some people manage with just one.
Although you might get by with two night in Malaga, it's not a small place. Any time you have just two nights in a city it's only one full day, and that can feel rushed. I try hard not to have any two-night stops.
I am not that much of an Algarve fan even at the optimal time of year (which is not Jan/Feb), so I can't really contribute much there, but as it stands you seem to be allowing 15 nights to cover five of Spain's most fabulous destinations and more than 10 nights on the Algarve (depending on how early you plan to be back in Lisbon). I'd definitely shift some time from the Algarve to Spain (starting with Seville and Toledo). Or to Evora. Or to Lisbon.
Other possibilities in Spain if you can be convinced that you've got an awful lot of time assigned to the Algarve would be Cadiz or a side-trip to Segovia from Madrid. Note, though, that central Spain (including the Madrid area) can be pretty cool in the winter. The average low temperatures in Madrid for January and February are down in the 30s. Seville and Malaga are about 15 degrees warmer. Granada and Cordoba cool off at night like Madrid.