how could I win this endgame?



I'm guessing you were playing white, so my advice is that you should try to keep your pawns protected in the endgame. Especially in this situation, where black would love to take all your pawns, when a king and rook versus a king, knight, and rook is a draw. I think you also could've tried to attack the black pawns with your king, because the king can become an attacking piece in the endgame. Though, honestly, I'd prefer someone better than me try to give you advice.
Well, it's a tough endgame. In general what you need to do is: watch out with trading pawns, cause they make a draw more likely. And be active. If you're not active, you won't be effectively playing with a piece up. Also, always look at your opponent's counterplay. Try and limit their counterplay. That being said, I do see how this endgame can get difficult.
I think the most room for improvement is around move 28. Here black doesn't seem to be having a clear plan. I would like to take a time-out there to improve my pieces. I'd also maybe like a move like b5 to clamp down on the queenside pawns. So maybe 28. b5, and then 29. Kd3 and maybe only then a move like Ne5. It's all about small improvements of our pieces here.
The move 31. Nb3 I really dislike. Where is that knight going? On b3 it's doing nothing and it's not helping out on the kingside. I'd want to have it on e5 and 31. Nf3 is possible because of 31. ... Rxg3, 32. Ne5+ winning the rook.
34. bxc5 is wrong, as it allows more pawn trades than are necessary. 34. Ne5 planning 35. Rf3 is much better. Note how white has a passive rook that really needs to be activated. When you're a piece up, black can't trade the rook, so you can easily take control over open files.
I think around move 38 it's gotten really hard with black being very active, your superpassive king and you having so few pawns left. You need to find a way for your king to get into the game and to get your pieces active. 38. Rd3 is not good in that regard. Maybe 38. Nf3, threatening 39. Ng5 (or 38. Nf7+, Ng5, but that might lead to Ke7-f6 for black, which I'd rather not encourage). After something like 38. Nf3, Ra4; 39. Ke2, Ra2+; 40. Kf1, Ra4; 41. Kf2, Ra2+; 42. Re2 I have found a way to get my king to f4 or to get it into play via Kg2-Kh3. After something like 38. Nf3, Ke7; 39. Ng5, Ra6; 40. Ke2, Kf6; 41. Nf3 I have gotten a little bit of an improvement, but it's still a long way to go after 41. ... Ra2+.
I guess at the end we're looking for a setup where white can play Nf3-g5-xe6 while the king is defending d4? I don't quite see how this would happen though if black moved his rook to the queenside.
All in all, to win this position, you need to not let them trade all your pawns, because it becomes more and more difficult with every pawn that gets traded.