You can factory reset your iPhone and wipe all its data in the Settings app. If you don't remember your password, you can use iTunes instead.
To sign out of iCloud on all of your devices at once, you can head to iCloud's website and change your password.