If you have a smartphone, there should be apps available to perform these tasks. Maybe an app to block just calls and another for just messages. If you search patiently, maybe you can even find an app that can perform both. Let me know which smartphone you have so I can give a few recommendations.
For non-smartphones, there are some phone models that have these functions built-in. If your phone doesn't have, you can contact your carrier and inquire if they offer such services.