Of course you can! I'm friends with a few exes.
Just remember to be mindful of them being a friend vs someone you want to hold onto, you know? A friend celebrates and grieve...