"How can I estimate how long a refactoring project will take?"
Longer than any estimate you make, probably.
I would suggest a few useful starting points.
If you are intending to change the entire codebase, then estimates should probably start at the same number of man-hours the existing edifice took to produce.
If you're intending to set a higher standard this time, with more complicated or subtle code than before, then increase the estimate from the starting point - I would suggest increasing the estimate only in integer multiples, under this heading.
There may be circumstances which reduce the estimate.
For example, if you wrote the existing codebase and now have many more years of business experience, that will considerably speed the redevelopment process because you'll already have a considerable understanding.
If technology has moved on significantly since the original development, and you can identify a specific feature that was once bespoke and difficult and is now trivial, that may speed the redevelopment.
If the scope of the redevelopment is clearly localised and not global to all existing code, then that may speed the project.
And if the existing codebase mostly consists of cruft, legacy remnants, or grotesque distortions, which can all be purged in the redevelopment, then something much simpler may result from redevelopment, and thus you can reduce the estimate by some fraction.
But you can see that you're usually dealing with very big numbers and wide margins of error.
Knowledge of a specific codebase, and knowledge of a particular kind of development, may alter estimates significantly, but in the abstract there is rarely any reason to deviate from the proven experience of how long some software took to write in the first place.
If you don't know where to start with estimating, start with that, and think carefully about whether that estimate is within your resources.