How to pick a phone for long usage? Is it possible to buy an Android phone for 5 years?
First, replaceable battery, yes.
But then, will I be able to use new and newer Android versions?
Yes, it is possible to buy an Android phone that will last for 5 years.  My phone has served me well for 7-8 years, so far, and I believe it will last even longer.
However, you can't tell what will happen in the future.  So, here's some other thoughts.
The phone will definitely need a replaceable battery as batteries go bad.
Best thing to do would be to buy a phone that is popular or that you believe will be popular in the future.
Custom ROMs are key, as already mentioned.  XDA is where you'd likely find custom ROMs.
If the phone is popular enough, then in the future, with more people owning the phone, it will be more likely that there will exist someone that is able to and willing to create and maintain a custom ROM.  However, with a phone that has many models, some models may get more or less attention.
Also, with a phone that is popular will likely mean that there will be more replacement parts available in the future...although a lot of phones, I believe, are being made to be less serviceable...so that more people replace their phones.
I have a Samsung Note 3 that was first released in September of 2013.  It had Android 4.4 and later Android 5.0 also.  Nothing after that.  I was OK with it, except that some apps stopped functioning or were updated, requiring newer Android versions.  Luckily, XDA had a custom ROM for Android 10 and now for Android 11.  I was also lucky that the person(s) creating and maintaining the ROM(s) has/have a Note 3 model compatible to mine.  It's fast enough and has most, if not all, of the things that most current phones have/do.  I replaced the battery with an extended battery and can get up to 7-10 days of usage by minimizing screen use.  Main thing it doesn't have is the upgraded cameras that are available now.  There are some other items too, such as fingerprint sensors missing.  Liked it so much, I bought a second hand one for $60.
You'll also probably want a phone that is sufficiently fast as future apps will likely be more &quot;intensive&quot;.  Another thing is that you'll probably want one with sufficient RAM/ROM so that future larger apps and ROMs will have enough free space.
Depending on what you'll be using the phone for, you might actually want to buy an older, released phone that meets some or all of the above.  I believe the replaceable battery will be the biggest item.  This way, you can verify whether ROMs are available, such as on XDA.  Also, chances are, if there's a custom ROM available, it's more likely that there will be future custom ROMs available for future versions of Android.