Setting page title and keywords from PHP code

You can use the wp_title filter to modify the HTML document title, and you can use the wp_head action to hook in a custom HTML meta link. e.g.:

<?php
function wpse46249_filter_wp_title( $title ) {
    // $title contains the default document title
    // output by WordPress. Modify it here however
    // you want.
    $some_custom_title_content="CUSTOM TITLE CONTENT HERE";
    // Now append it to the default
    $custom_title = $title . $some_custom_title_content;
    // Then return the result
    return $custom_title;
}
add_filter( 'wp_title', 'wpse46249_filter_wp_title' );

function wpse46249_add_meta_link() {
    echo '<meta name="keywords" content="INSERT KEYWORDS HERE" />';
}
add_action( 'wp_head', 'wpse46249_add_meta_link' );
?>

These callbacks can be added to a Plugin, to keep them safe from Theme switching.

For further reference, I would recommend taking a look at how the popular SEO Plugins implement these extensions.